Documentation
¶
Overview ¶
Package scheduler provides a simple, humans-friendly way to schedule the execution of the go function. It includes delay execution and periodic execution.
Index ¶
- Constants
- Variables
- func InitJobSched(jobType string) map[string]int
- type Job
- type JobSet
- type JobTicker
- type JobTimer
- type Scheduler
- func (s *Scheduler) CancelJob(id string) error
- func (s *Scheduler) Delay() *Job
- func (s *Scheduler) Every() *Job
- func (s *Scheduler) JobDone(id string) (bool, error)
- func (s *Scheduler) JobSched(id string) (map[string]int, error)
- func (s *Scheduler) JobType(id string) (string, error)
- func (s *Scheduler) PendingJob(id string) (*Job, error)
Constants ¶
View Source
const ( // Delay represents job type, the job will be delayed execute once according to job sched Delay = "Delay" // Every represents job type, the job will be cycled execute according to job sched Every = "Every" // Key of job sched Second = "Second" Minute = "Minute" Hour = "Hour" Day = "Day" Weekday = "Weekday" Month = "Month" // EveryRune is value of job sched, like "*" in cron, represents every // second/minute/hour/day/weekday/month. EveryRune = -1 )
Variables ¶
View Source
var ( // ErrPendingJob is returned when the pending job not exist ErrPendingJob = errors.New("pending job not exist") // ErrOverlength is returned when the job size over maxJobSetSize variable ErrOverlength = errors.New("job set size overlength") // ErrJobType is returned when the job type not exist, // job type is one of Delay and Every. ErrJobType = errors.New("job type not exist") // ErrJobSched is returned when the job sched not exist, // under normal circumstances, this error will not occur, // unless the key definition of job sched is incorrectly modified. ErrJobSched = errors.New("job sched not exist") // ErrTimeNegative is returned when the time argument is negative ErrTimeNegative = errors.New("time argument can not be negative") // ErrDupJobID is returned when the generateID generates the same id ErrDupJobID = errors.New("Duplicate job id") // ErrAlreadyComplayed is returned when cancel a completed job ErrAlreadyComplayed = errors.New("Job hash been completed") // ErrCancelJob is returned when time.Timer.Stop function occur error ErrCancelJob = errors.New("cancel job failed") // ErrRangeSecond is returned when Second method argument is not int ErrRangeSecond = errors.New("argument 0 <= n <= 59 in Second method") // ErrRangeMinute is returned when Minute method argument is not int ErrRangeMinute = errors.New("argument 0 <= n <= 59 in Minute method") // ErrRangeHour is returned when Hour method argument is not int ErrRangeHour = errors.New("argument 0 <= n <= 23 in Hour method") // ErrRangeDay is returned when Day method argument is not int ErrRangeDay = errors.New("argument 1 <= n <= 31 in Day method") // ErrRangeWeekday is returned when Weekday method argument is not int ErrRangeWeekday = errors.New("argument 0 <= n <= 6 in Weekday method") // ErrRangeMonth is returned when Month method argument is not int ErrRangeMonth = errors.New("argument 1 <= n <= 12 in Month method") ErrRangeExceeds = errors.New("job delay duration takes more than 24 hour") // EmptyJobType represents an empty job type EmptyJobType = "" // EmptySched represents an empty job sched EmptySched = map[string]int{} )
Functions ¶
func InitJobSched ¶
InitJobSched initiate job sched by job type
Types ¶
type Job ¶
type Job struct { ID string // unique id Type string // job type // Sched is a job sched, like cron style but the order of time is not // fixed, can be arranged and combined at will. Sched map[string]int JTimer *JobTimer // JobTimer JTicker *JobTicker // JobTicker // contains filtered or unexported fields }
Job is an abstraction of a scheduling task.
type JobSet ¶
type JobSet struct {
// contains filtered or unexported fields
}
JobSet stores pending jobs and completed jobs and it is concurrent safly.
type JobTicker ¶
type JobTicker struct { ID string // unique id // contains filtered or unexported fields }
JobTicker is the wrapper for time.Ticker, one job corresponds to a JobTicker.
type JobTimer ¶
type JobTimer struct { ID string // unique id // contains filtered or unexported fields }
JobTimer is the wrapper for time.Timer, one job corresponds to a JobTimer.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler is responsible for scheduling jobs.
func NewScheduler ¶
NewScheduler new Scheduler instance.
Click to show internal directories.
Click to hide internal directories.