Documentation ¶
Index ¶
- Variables
- func CheckQueue(job string) bool
- func UpdateIsRunningSchedule(job Job, isrunning bool)
- func UpdateStartedSchedule(job Job)
- type DispatchCron
- type DispatchTicker
- type Dispatcher
- func (d *Dispatcher) Dispatch(name string, run func()) error
- func (d *Dispatcher) DispatchCron(name string, run func(), cronStr string) (*DispatchCron, error)
- func (d *Dispatcher) DispatchEvery(name string, run func(), interval time.Duration) (*DispatchTicker, error)
- func (d *Dispatcher) DispatchIn(name string, run func(), duration time.Duration) error
- func (d *Dispatcher) Start()
- func (d *Dispatcher) Stop()
- type DispatcherQueue
- type Job
- type JobSchedule
- type JobSchedules
- type Worker
Constants ¶
This section is empty.
Variables ¶
var Mu sync.Mutex
Functions ¶
func CheckQueue ¶
func UpdateIsRunningSchedule ¶
func UpdateStartedSchedule ¶
func UpdateStartedSchedule(job Job)
Types ¶
type DispatchCron ¶
type DispatchCron struct { Cron *cron.Cron // contains filtered or unexported fields }
DispatchCron represents a dispatched cron job that executes using cron expression formats.
func (*DispatchCron) Remove ¶
func (c *DispatchCron) Remove(id cron.EntryID)
func (*DispatchCron) Start ¶
func (c *DispatchCron) Start()
func (*DispatchCron) Stop ¶
func (c *DispatchCron) Stop()
Stops ends the execution cycle for the given cron.
type DispatchTicker ¶
DispatchTicker represents a dispatched job ticker that executes on a given interval. This provides a means for stopping the execution cycle from continuing.
func (*DispatchTicker) Stop ¶
func (dt *DispatchTicker) Stop()
Stop ends the execution cycle for the given ticker.
type Dispatcher ¶
type Dispatcher struct { Tickers []*DispatchTicker Crons []*DispatchCron DispatchQueue DispatcherQueue // contains filtered or unexported fields }
Dispatcher maintains a pool for available workers and a job queue that workers will process
func NewDispatcher ¶
func NewDispatcher(name string, maxWorkers int, maxQueue int) *Dispatcher
NewDispatcher creates a new dispatcher with the given number of workers and buffers the job queue based on maxQueue. It also initializes the channels for the worker pool and job queue
func (*Dispatcher) Dispatch ¶
func (d *Dispatcher) Dispatch(name string, run func()) error
Dispatch pushes the given job into the job queue. The first available worker will perform the job
func (*Dispatcher) DispatchCron ¶
func (d *Dispatcher) DispatchCron(name string, run func(), cronStr string) (*DispatchCron, error)
DispatchEvery pushes the given job into the job queue each time the cron definition is met
func (*Dispatcher) DispatchEvery ¶
func (d *Dispatcher) DispatchEvery(name string, run func(), interval time.Duration) (*DispatchTicker, error)
DispatchEvery pushes the given job into the job queue continuously at the given interval
func (*Dispatcher) DispatchIn ¶
func (d *Dispatcher) DispatchIn(name string, run func(), duration time.Duration) error
DispatchIn pushes the given job into the job queue after the given duration has elapsed
func (*Dispatcher) Start ¶
func (d *Dispatcher) Start()
Start creates and starts workers, adding them to the worker pool. Then, it starts a select loop to wait for job to be dispatched to available workers
func (*Dispatcher) Stop ¶
func (d *Dispatcher) Stop()
Stop ends execution for all workers/tickers and closes all channels, then removes all workers/tickers
type DispatcherQueue ¶
var GlobalQueue DispatcherQueue
func (*DispatcherQueue) AddQueue ¶
func (d *DispatcherQueue) AddQueue(job Job)
func (*DispatcherQueue) RemoveQueue ¶
func (d *DispatcherQueue) RemoveQueue(job Job)
func (*DispatcherQueue) UpdateStartedQueue ¶
func (d *DispatcherQueue) UpdateStartedQueue(job Job)
type Job ¶
type Job struct { Queue string ID string Added time.Time Started time.Time Name string SchedulerId string Run func() `json:"-"` }
Job represents a runnable process, where Start will be executed by a worker via the dispatch queue
type JobSchedule ¶
type JobSchedules ¶
type JobSchedules struct {
Schedule map[string]JobSchedule
}
var GlobalSchedules JobSchedules
func (*JobSchedules) AddQueue ¶
func (d *JobSchedules) AddQueue(job JobSchedule)
func (*JobSchedules) RemoveQueue ¶
func (d *JobSchedules) RemoveQueue(job JobSchedule)
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker attaches to a provided worker pool, and looks for jobs on its job channel
func NewWorker ¶
NewWorker creates a new worker using the given id and attaches to the provided worker pool. It also initializes the job/quit channels