Documentation ¶
Index ¶
- Variables
- type Job
- type JobJSON
- type Key
- type Table
- func (t *Table) AddJob(ctx context.Context, key Key, interval, delay duration.Duration, ...) (*Job, error)
- func (t *Table) Count(ctx context.Context) (int64, error)
- func (t *Table) Create(ctx context.Context) error
- func (t *Table) DeleteInstance(ctx context.Context, id uint32) error
- func (t *Table) DeleteJob(ctx context.Context, key Key) error
- func (t *Table) DisableJob(ctx context.Context, key Key) (*Job, error)
- func (t *Table) Drop(ctx context.Context) error
- func (t *Table) EnableJob(ctx context.Context, key Key) (*Job, error)
- func (t *Table) Front(ctx context.Context, instanceID uint32) (*Job, error)
- func (t *Table) Get(ctx context.Context, path, body string) (*Job, error)
- func (t *Table) Instances(ctx context.Context) (int64, error)
- func (t *Table) Lag(ctx context.Context) (int64, error)
- func (t *Table) Pending(ctx context.Context) (int64, error)
- func (t *Table) Running(ctx context.Context) (int64, error)
- func (t *Table) UpdateInstance(ctx context.Context, id uint32) error
- func (t *Table) UpdateInstanceID(ctx context.Context, key Key, instanceID uint32) error
- func (t *Table) UpdateNextRun(ctx context.Context, key Key, randFactor float64, retryParams *retry.Retry) error
Constants ¶
This section is empty.
Variables ¶
var ErrNotExist = errors.New("job does not exist")
Functions ¶
This section is empty.
Types ¶
type Job ¶
type Job struct { Key // Interval is the duration between each POST to the endpoint. // Interval is "" for one-off jobs. Interval duration.Duration // Interval is relative to the Location. // Format is the tz database name, such as America/Los_Angeles. Location *time.Location // NextRun is the next run time of the job, including retries. NextRun sql.NullTime // NextSched is the next time the job is scheduled to run, regardless of retries. NextSched time.Time // Job is running if not nil. InstanceID *uint32 }
Job is the record stored in jobs table. Primary key for the table is Key.
func (*Job) MarshalJSON ¶
type Table ¶
type Table struct { SkipLocked bool FixedIntervals bool Clk *clock.Clock // contains filtered or unexported fields }
func (*Table) AddJob ¶
func (t *Table) AddJob(ctx context.Context, key Key, interval, delay duration.Duration, location *time.Location, nextRun time.Time) (*Job, error)
AddJob inserts a job into the scheduler table.
func (*Table) DeleteInstance ¶
DeleteInstance removes an entry from the list of active instances.
func (*Table) DisableJob ¶
DisableJob prevents a job from running by setting next_run to NULL, while preserving the value of next_sched.
func (*Table) EnableJob ¶
EnableJob marks the job as enabled by setting next_run to next_sched.
If next_sched is in the past, the job will then be picked up for execution immediately.
With FixedIntervals enabled, next_sched is advanced by the value of interval until it's in the future and next_run matches it.
func (*Table) Front ¶
Front returns the next scheduled job from the table, based on the value of next_run, and claims it for the calling instance.
func (*Table) Lag ¶
Lag returns the number of seconds passed from the execution time of the oldest pending job.
func (*Table) UpdateInstance ¶
UpdateInstance adds the instance to the list of active instances, and clears out any inactive instances from the list, such as instances that were unable to call DeleteInstance during shutdown.
func (*Table) UpdateInstanceID ¶
UpdateInstanceID claims a job for an instance.
func (*Table) UpdateNextRun ¶
func (t *Table) UpdateNextRun(ctx context.Context, key Key, randFactor float64, retryParams *retry.Retry) error
UpdateNextRun sets next_run and next_sched, and unclaims it from an instance.
With default settings, next_sched and next_run are set to now+delay.
With FixedIntervals enabled, next_sched is advanced by the value of interval until it's in the future and next_run matches it.
If this is a retry, next_run is set to a value based on retry parameters and next_sched is not adjusted.
If UpdateNextRun is called on a disabled job, as many happen when a job has been disabled during execution, next_sched will advance but next_run will remain NULL.