Documentation
¶
Index ¶
Constants ¶
View Source
const DefaultTableName = "works"
Variables ¶
View Source
var ( ErrNoWork = errors.New("there is no work to do") ErrFailToUpdateStatus = errors.New("failed to update status") ErrFailToAcquireWork = errors.New("failed to acquire work") ErrFailToFinalizeAcquire = errors.New("failed to acquire work") ErrFailToInitWorkScheduler = errors.New("failed to initialize work scheduler") )
Functions ¶
func NewDBConnection ¶
Types ¶
type SchedulerConfig ¶
type SchedulerConfig struct {
DurationBeforeSequence time.Duration
SchedulerCheckingInterval string
SequenceGenerator SequenceFunc
}
type SequenceFunc ¶
SequenceFunc used to generate sequence for each work.
type Work ¶
type Work struct {
// unique name for the work
Name string
// cron expression of when the worker is going to be executed
Cron string
// number of times the work must be executed.
// Note that it is only guaranteed that
// the number of workers acquiring this work not to surpass this value.
MaxRun int64
// contains filtered or unexported fields
}
type WorkResultFunc ¶
type WorkResultFunc func()
type WorkScheduler ¶
type WorkScheduler struct {
// contains filtered or unexported fields
}
func NewScheduler ¶
func NewScheduler(db *db, works []*Work, config *SchedulerConfig) (*WorkScheduler, error)
func (*WorkScheduler) StartSchedule ¶
func (w *WorkScheduler) StartSchedule()
func (*WorkScheduler) StopSchedule ¶
func (w *WorkScheduler) StopSchedule()
type WorkStatus ¶
type WorkStatus int8
const ( // Queued Initial status of work before acquiring. Queued WorkStatus = iota + 1 // Running indicates that the work is running by a worker. Running // Success status of work if the worker finish the work successfully. Success // Failed status of work if the worker finish the work with an error. Failed )
type WorkSync ¶
type WorkSync struct {
// contains filtered or unexported fields
}
func (*WorkSync) AcquireWork ¶
func (w *WorkSync) AcquireWork(workName, sequence string) (WorkResultFunc, WorkResultFunc, error)
AcquireWork check database and try to acquire a work. It returns an error if there is no work to acquire or fail in the process of acquiring a work. If the acquiring process is successful, it returns success and fail functions to determine the result of the work. Calling either of these functions will update the status of the work in the database.
Click to show internal directories.
Click to hide internal directories.
