Documentation
¶
Index ¶
- type Job
- type SimpleTask
- type Task
- type TaskManager
- func (tm *TaskManager) ErrorChannel() <-chan error
- func (tm *TaskManager) RemoveJob(jobID string) error
- func (tm *TaskManager) ReplaceJob(newJob Job) error
- func (tm *TaskManager) ScheduleFunc(function func() error, cadence time.Duration) (string, error)
- func (tm *TaskManager) ScheduleJob(job Job) error
- func (tm *TaskManager) ScheduleTask(task Task, cadence time.Duration) (string, error)
- func (tm *TaskManager) ScheduleTasks(tasks []Task, cadence time.Duration) (string, error)
- func (tm *TaskManager) Stop()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Job ¶
type Job struct { Cadence time.Duration // Time between executions of the job Tasks []Task // Tasks in the job ID string // Unique ID for the job NextExec time.Time // The next time the job should be executed // contains filtered or unexported fields }
Job is a container for a group of tasks, with a unique ID and a cadence for scheduling.
type SimpleTask ¶ added in v0.2.0
type SimpleTask struct {
// contains filtered or unexported fields
}
SimpleTask is a task that executes a function.
func (SimpleTask) Execute ¶ added in v0.2.0
func (st SimpleTask) Execute() error
Execute executes the function and returns the error.
type Task ¶
type Task interface {
Execute() error
}
Task is an interface for tasks that can be executed.
type TaskManager ¶ added in v0.2.0
TaskManager manages task scheduling and execution. Tasks are scheduled within Jobs, and the manager dispatches scheduled jobs to a worker pool for execution.
func New ¶ added in v0.2.0
func New() *TaskManager
New creates, starts and returns a new TaskManager.
func (*TaskManager) ErrorChannel ¶ added in v0.2.0
func (tm *TaskManager) ErrorChannel() <-chan error
ErrorChannel returns a read-only channel for reading errors from task execution.
func (*TaskManager) RemoveJob ¶ added in v0.2.0
func (tm *TaskManager) RemoveJob(jobID string) error
RemoveJob removes a job from the TaskManager.
func (*TaskManager) ReplaceJob ¶ added in v0.2.0
func (tm *TaskManager) ReplaceJob(newJob Job) error
ReplaceJob replaces a job in the TaskManager's queue with a new job, if their ID:s match. The new job's NextExec will be overwritten by the old job's, to preserve the TaskManager's schedule. Use this function to update a job's tasks without changing its schedule.
func (*TaskManager) ScheduleFunc ¶ added in v0.2.0
ScheduleFunc takes a function and adds it to the TaskManager in a Job. Creates and returns a randomized ID, used to identify the Job within the task manager.
func (*TaskManager) ScheduleJob ¶ added in v0.2.0
func (tm *TaskManager) ScheduleJob(job Job) error
ScheduleJob adds a job to the TaskManager. A job is a group of tasks that are scheduled to execute at a regular interval. The tasks in the job are executed in parallel, but the job's cadence determines when the job is executed. The function returns a job ID that can be used to identify the job within the TaskManager. Job requirements: - Cadence must be greater than 0 - Job must have at least one task - NextExec must not be more than one cadence old, set to time.Now() for instant execution - Job must have an ID, unique within the TaskManager
func (*TaskManager) ScheduleTask ¶ added in v0.2.0
ScheduleTask takes a Task and adds it to the TaskManager in a Job. Creates and returns a randomized ID, used to identify the Job within the task manager.
func (*TaskManager) ScheduleTasks ¶ added in v0.2.0
ScheduleTasks takes a slice of Task and adds them to the TaskManager in a Job. Creates and returns a randomized ID, used to identify the Job within the task manager.
func (*TaskManager) Stop ¶ added in v0.2.0
func (tm *TaskManager) Stop()
Stop signals the TaskManager to stop processing tasks and exit. Note: blocks until the TaskManager, including all workers, has completely stopped.