Documentation ¶
Index ¶
- Constants
- Variables
- type ProcessFunc
- type Scheduler
- type SchedulerOpt
- func WithMaxRetries(n int) SchedulerOpt
- func WithMaxTasks(n int) SchedulerOpt
- func WithMaxWorkers(n int) SchedulerOpt
- func WithName(name string) SchedulerOpt
- func WithQueueLength(n int) SchedulerOpt
- func WithQueueLoopSeconds(n float64) SchedulerOpt
- func WithRetryAfterSeconds(n float64) SchedulerOpt
- func WithVerbose() SchedulerOpt
- func WithWorkerTaskBuffer(n int) SchedulerOpt
- func WithWorkerTerminationTimeoutSeconds(n float64) SchedulerOpt
- type Task
- type TaskInterface
- type Worker
Constants ¶
const ( // DefaultRetryAfter sets default value for retry DefaultRetryAfter = 30 * time.Second // DefaultQueueLength DefaultQueueLength = 1000 // DefaultMaxRetries set default max retries for scheduler DefaultMaxRetries = -1 )
Variables ¶
var ( // ErrorDuplicate is returnd for duplicated tasks ErrorDuplicate = errors.New("Dropped task as duplicate") )
Functions ¶
This section is empty.
Types ¶
type ProcessFunc ¶
type ProcessFunc func(context.Context, TaskInterface) error
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
func NewScheduler ¶
func NewScheduler(opts ...SchedulerOpt) *Scheduler
func (*Scheduler) ProcessQueue ¶
func (s *Scheduler) ProcessQueue()
ProcessQueue trigger queue processing
func (*Scheduler) WorkerCount ¶
type SchedulerOpt ¶
type SchedulerOpt func(*Scheduler)
func WithMaxRetries ¶
func WithMaxRetries(n int) SchedulerOpt
WithMaxRetries sets number or retries for tasks use WithMaxRetries(0) to disable any retry (tak will run only once) WithMaxRetries(1) means task will be retried once Default value is -1 meaning retry forever
func WithMaxWorkers ¶
func WithMaxWorkers(n int) SchedulerOpt
WithMaxWorkers set maxWorkers for scheduler
func WithQueueLength ¶
func WithQueueLength(n int) SchedulerOpt
WithQueueLength defines queue lenght for tasks Required to be > 10
func WithQueueLoopSeconds ¶
func WithQueueLoopSeconds(n float64) SchedulerOpt
WithQueueLoopSeconds sets how often scheduler read waiting queue
func WithRetryAfterSeconds ¶
func WithRetryAfterSeconds(n float64) SchedulerOpt
WithRetryAfterSeconds set how long scheduler waits before retrying failed task
func WithWorkerTaskBuffer ¶
func WithWorkerTaskBuffer(n int) SchedulerOpt
WithWorkerTaskBuffer set buffer lenght for task
func WithWorkerTerminationTimeoutSeconds ¶
func WithWorkerTerminationTimeoutSeconds(n float64) SchedulerOpt
WithWorkerTerminationTimeoutSeconds defines how long we wait for worker
type Task ¶
type Task struct { // Unique task identification ID string // Queue key, default will be used when empty Key string // Object which will be passed to worker Obj TaskInterface // Timing options Queued time.Time Started time.Time Finished time.Time // Task result Result error RetryAfter time.Time // How long wait before retry RetryTimeout time.Duration // Function for processing this task // It will be executed by worker ProcessFunc ProcessFunc // contains filtered or unexported fields }
func NewTask ¶
func NewTask(key string, obj TaskInterface, pf ProcessFunc) *Task
func (*Task) GetFailures ¶
GetFailures returns number of task failures
func (*Task) GetRetryAfter ¶
GetRetryAfter returns retry after
func (*Task) SetFailures ¶
SetFailures sets number of failures direclty It's useful when external tool is adding task to schedulers and this task was already failed before.
type TaskInterface ¶
type TaskInterface interface{}