Documentation ¶
Overview ¶
Package slate is an in memory non persistent scheduler that simplifies handling repeat method calls. slate allows you to
- Run a job n number of times
- At a predefined start time
- At every n unit of time (nano, micro, milli seconds, minutes...)
- With automatic expirations
slate also keeps track of these jobs running asynchronously in go routines so you can forcefully stop them at anytime.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDurationZero occurs when adding a new job, but the every duration is zero. ErrDurationZero = NewSlateError("Task duration of zero is not allowed.") // ErrExpirationInPast occurs when submitting a new schedule entry with an expiration in the past ErrExpirationInPast = NewSlateError("Schedule entry submitted with a Expires value in the past.") // ErrInvalidTiming occurs when submitting a new schedule entry with an expiration less than the begins time plus the every duration ErrInvalidTiming = NewSlateError("Schedule entry submitted cannot run due to Begins, Expires and Every values.") // ErrFunctionParamMismatch occurs when the fn params passed do not match the fn params required. ErrFunctionParamMismatch = NewSlateError("Mismatch in params passed to assigned Fn.") // ErrInvalidFunction occurs when the fn param bound to a schedule entry is not a valid func. ErrInvalidFunction = NewSlateError("Fn assigned not of type func.") // ErrMaximumRun occurs when a running count breaches the uint64 limit. ErrMaximumRun = NewSlateError("The runners Every ticker has reached the maximum uint64 number of ticks.") // ErrOrphanedEvent occurs when a running event cannot find the schedule that should contain it. ErrOrphanedEvent = NewSlateError("The executing event is no longer assigned to it's schedule. Orphaned.") // ErrScheduleEntryDuplicateID occurs when submitting a new schedule entry with a id that already exists on the schedule. ErrScheduleEntryDuplicateID = NewSlateError("Schedule entry submitted with a duplicate ID.") // ErrScheduleEntryNotFound occurs when unable to find a job runner by id. ErrScheduleEntryNotFound = NewSlateError("Scheduled entry not found.") // ErrScheduleNotFound occurs when unable to find a schedule by name. ErrScheduleNotFound = NewSlateError("Schedule not found.") )
Functions ¶
func IsSlateError ¶
IsSlateError will return true on slateError instance.
func NewSlateError ¶
NewSlateError will return a new SlateError instance.
Types ¶
type EntryID ¶
type EntryID string
EntryID is the identifier to reference a Schedule Entry
func GenerateEntryID ¶
GenerateEntryID will return a unique entry ID. You can always assign your own string ID to schedules. This is especially useful when using multiple schedules that pertain to a universal ID, such as a user_id.
type Manager ¶
Manager is a convenience struct to manage many Schedules
func NewManager ¶
func NewManager() *Manager
NewManager will create a new schedule manager. Managers are simply a wrapper for multiple schedule to help callers organise their workflow. If you only require a single schedule, then call NewSchedule() and work with directly.
func (*Manager) Drop ¶
Drop will stop and remove all related jobs on the schedule before removing the schedule from this manager.
type Schedule ¶
type Schedule struct { Config ScheduleConfig sync.Mutex // contains filtered or unexported fields }
Schedule is the default struct that houses job runners.
func NewSchedule ¶
func NewSchedule(cfg ...ScheduleConfig) *Schedule
NewSchedule will return a new Scheduler instance. If nil config is passed, the defaults are used.
func (*Schedule) Drop ¶
Drop will first stop any job if applicable and then remove the entry from this schedule.
func (*Schedule) EntryStats ¶
func (s *Schedule) EntryStats(ID EntryID) ScheduleEntryStats
EntryStats will return a snapshot of stats for a scheduleEntry on this schedule instance. Note that this will lock the internal runner so be mindful of multiple calls
func (*Schedule) Reset ¶
func (s *Schedule) Reset()
Reset will stop and remove ALL jobs from this schedule.
func (*Schedule) Stats ¶
func (s *Schedule) Stats() ScheduleStats
Stats will return a snapshot of this schedules running events. Note that this will lock the schedule so be mindful of multiple calls
type ScheduleConfig ¶
type ScheduleConfig struct { DisallowDuplicateEntryID bool FlushEvery time.Duration EntryRetention time.Duration }
ScheduleConfig contains all available config options for a schedule
func NewScheduleConfig ¶
func NewScheduleConfig(opts ...ScheduleConfigOption) ScheduleConfig
NewScheduleConfig will return a Config for a schedule. Takes variadic ScheduleConfigOption
type ScheduleConfigOption ¶
type ScheduleConfigOption func(*ScheduleConfig)
ScheduleConfigOption is a func used to bind schedule config options
func WithDisallowDuplicateEntryID ¶
func WithDisallowDuplicateEntryID(disallow bool) ScheduleConfigOption
WithDisallowDuplicateEntryID will bind the config option to (dis)allow duplicate schedule entry IDs
func WithEntryRetention ¶
func WithEntryRetention(retention time.Duration) ScheduleConfigOption
WithEntryRetention will bind the config option to retain entries on a schedule.
func WithFlushEvery ¶
func WithFlushEvery(every time.Duration) ScheduleConfigOption
WithFlushEvery will bind the config option to flush completed/stopped schedule entries.
type ScheduleEntry ¶
type ScheduleEntry struct { // Ensure that this entry does not run before the begins time. Begins time.Time // Cap the number of times this entry will run. Cap uint64 // Run this entry **every... Every time.Duration // Ensure that this entry does not run after the expires time. Expires time.Time // function to be called on **every. Wrap in closure for funcs with args. Fn func() // The generated or user assigned ID for this entry ID EntryID // contains filtered or unexported fields }
ScheduleEntry is the default struct to assign running parameters.
type ScheduleEntryStats ¶
type ScheduleEntryStats struct { Completed time.Time Err error RunningCount uint64 Started time.Time State string Stopped time.Time }
ScheduleEntryStats return stats about a Schedule Entry instance
type ScheduleStats ¶
type ScheduleStats struct { Config struct { AllowDuplicateEntryID bool EntryRetention time.Duration FlushEvery time.Duration } EntryCount int CapBreachedCount int ErrorCount int ExpiredCount int PendingCount int RunningCount int StoppedCount int }
ScheduleStats return stats about a Schedule instance