clockwork

package module
v0.0.0-...-353816f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2018 License: MIT Imports: 6 Imported by: 0

README

clockwork

GoDoc Go Report Card Coverage

A simple and intuitive scheduling library in Go.

Inspired by python's schedule and ruby's clockwork libraries.

Example use

package main

import (
	"fmt"
	"github.com/whiteshtef/clockwork"
)

func main() {
	sched := clockwork.NewScheduler()

	sched.Schedule().Every(10).Seconds().Do(something)
	sched.Schedule().Every(3).Minutes().Do(something)
	sched.Schedule().Every(4).Hours().Do(something)
	sched.Schedule().Every(2).Days().At("12:32").Do(something)
	sched.Schedule().Every(12).Weeks().Do(something)

	sched.Schedule().Every().Second().Do(something) // Every() is "shorthand" for Every(1)
	sched.Schedule().Every().Monday().Do(something)
	sched.Schedule().Every().Saturday().At("8:00").Do(something)

	sched.Run()
}

func something() {
	fmt.Println("foo")

}

The package uses go dep for dependency management.

Documentation

Overview

Package clockwork enables simple and intuitive scheduling in Go.

Examples:

sched.Schedule().Every(10).Seconds().Do(something)
sched.Schedule().Every(3).Minutes().Do(something)
sched.Schedule().Every(4).Hours().Do(something)
sched.Schedule().Every(2).Days().At("12:32").Do(something)
sched.Schedule().Every(12).Weeks().Do(something)
sched.Schedule().Every(1).Monday().Do(something)
sched.Schedule().Every(1).Saturday().At("8:00").Do(something)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job struct {
	// contains filtered or unexported fields
}

Job struct handles all the data required to schedule and run jobs.

func (*Job) AddDesc

func (j *Job) AddDesc(d string) *Job

func (*Job) At

func (j *Job) At(t string) *Job

At method fills the given Job struct atHout and atMinute fields with the provided information

func (*Job) Day

func (j *Job) Day() *Job

Day method fills the given job struct with days

func (*Job) Days

func (j *Job) Days() *Job

Days method fills the given job struct with days

func (*Job) Desc

func (j *Job) Desc() string

func (*Job) Do

func (j *Job) Do(function func()) string

Do method fills the given job struct with the function pointer to the job (user provided task) itself.

func (*Job) Every

func (j *Job) Every(frequencies ...int) *Job

Every is a method that fills the given Job struct with the given frequency

func (*Job) EverySingle

func (j *Job) EverySingle() *Job

EverySingle is deprecated predecessor to Every()

func (*Job) Friday

func (j *Job) Friday() *Job

Friday method fills the given job struct with friday

func (*Job) Hour

func (j *Job) Hour() *Job

Hour method fills the given job struct with hours

func (*Job) Hours

func (j *Job) Hours() *Job

Hours method fills the given job struct with hours

func (*Job) ID

func (j *Job) ID() string

func (*Job) Info

func (j *Job) Info() JobInfo

func (*Job) Minute

func (j *Job) Minute() *Job

Minute method fills the given job struct with minutes

func (*Job) Minutes

func (j *Job) Minutes() *Job

Minutes method fills the given job struct with minutes

func (*Job) Monday

func (j *Job) Monday() *Job

Monday method fills the given job struct with monday

func (*Job) Saturday

func (j *Job) Saturday() *Job

Saturday method fills the given job struct with saturday

func (*Job) Second

func (j *Job) Second() *Job

Second method fills the given job struct with seconds

func (*Job) Seconds

func (j *Job) Seconds() *Job

Seconds method fills the given job struct with seconds

func (*Job) Stop

func (j *Job) Stop()

func (*Job) Stopped

func (j *Job) Stopped() bool

func (*Job) Sunday

func (j *Job) Sunday() *Job

Sunday method fills the given job struct with sunday

func (*Job) Thursday

func (j *Job) Thursday() *Job

Thursday method fills the given job struct with thursday

func (*Job) Tuesday

func (j *Job) Tuesday() *Job

Tuesday method fills the given job struct with tuesday

func (*Job) Wednesday

func (j *Job) Wednesday() *Job

Wednesday method fills the given job struct with wednesday

func (*Job) Week

func (j *Job) Week() *Job

Week method fills the given job struct with weeks

func (*Job) Weeks

func (j *Job) Weeks() *Job

Weeks method fills the given job struct with weeks

type JobInfo

type JobInfo = map[string]string

type LogLevel

type LogLevel = uint8

type Logger

type Logger interface {
	Output() io.Writer
	SetOutput(w io.Writer)
	Prefix() string
	SetPrefix(p string)
	Level() LogLevel
	SetLevel(v LogLevel)
	Print(i ...interface{})
	Printf(format string, args ...interface{})
	Debug(i ...interface{})
	Debugf(format string, args ...interface{})
	Info(i ...interface{})
	Infof(format string, args ...interface{})
	Warn(i ...interface{})
	Warnf(format string, args ...interface{})
	Error(i ...interface{})
	Errorf(format string, args ...interface{})
	Fatal(i ...interface{})
	Fatalf(format string, args ...interface{})
	Panic(i ...interface{})
	Panicf(format string, args ...interface{})
}

Logger defines the logging interface.

type Scheduler

type Scheduler struct {
	// contains filtered or unexported fields
}

Scheduler type is used to store a group of jobs (Job structs)

func NewScheduler

func NewScheduler(logger Logger) Scheduler

NewScheduler creates and returns a new Scheduler

func (*Scheduler) AllJobs

func (s *Scheduler) AllJobs() []Job

func (*Scheduler) GetJob

func (s *Scheduler) GetJob(id string) *Job

func (*Scheduler) Run

func (s *Scheduler) Run()

Run method on the Scheduler type runs the scheduler. This is a blocking method, and should be run as a goroutine.

func (*Scheduler) Schedule

func (s *Scheduler) Schedule() *Job

Schedule method on the Scheduler creates a new Job and prepares is for "filling"

func (*Scheduler) Size

func (s *Scheduler) Size() int

func (*Scheduler) Stop

func (s *Scheduler) Stop()

type TimeUnit

type TimeUnit int

TimeUnit is an numeration used for handling time units internally.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL