Documentation ¶
Overview ¶
Package worker provides a simple asynchronous worker queue.
Index ¶
- type Job
- type JobFunc
- type Scheduler
- func (s *Scheduler) Loop()
- func (s *Scheduler) RepeatEvery(j Job, d time.Duration) Job
- func (s *Scheduler) RepeatFuncEvery(j func() error, d time.Duration) Job
- func (s *Scheduler) Schedule(j Job) error
- func (s *Scheduler) ScheduleAt(j Job, t time.Time) error
- func (s *Scheduler) ScheduleFunc(j func() error) error
- func (s *Scheduler) ScheduleFuncAt(j func() error, t time.Time) error
- func (s *Scheduler) Shutdown() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Job ¶
type Job interface { // Perform invokes the job. Perform() error }
Job defines the interface for performing asynchronous work.
type JobFunc ¶
type JobFunc func() error
JobFunc allows bare functions to implement the Job interface.
type Scheduler ¶
type Scheduler struct { // Acceptable time to wait before forcefully quitting when shutting down // gracefully. ShutdownTimeout time.Duration // contains filtered or unexported fields }
Scheduler is the entry-point for scheduling jobs to run asynchronously.
func NewWithTick ¶
NewWithTick creates a new scheduler with a tick duration of delay.
func (*Scheduler) Loop ¶
func (s *Scheduler) Loop()
Loop begins a worker goroutine that takes care of running any jobs.
func (*Scheduler) RepeatEvery ¶
RepeatEvery wraps a job, rescheduling it after each successful run.
func (*Scheduler) RepeatFuncEvery ¶
RepeatFuncEvery is a convenience method for wrapping a bare func as a repeated job.
func (*Scheduler) ScheduleAt ¶
ScheduleAt adds a job to be performed at a specific time.
func (*Scheduler) ScheduleFunc ¶
ScheduleFunc is a convenience method accepting a function as a job.
func (*Scheduler) ScheduleFuncAt ¶
ScheduleFuncAt is a convenience method for adding a bare func as a job.