table

package
v3.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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) Enabled

func (j *Job) Enabled() bool

func (*Job) MarshalJSON

func (j *Job) MarshalJSON() ([]byte, error)

func (*Job) OneOff

func (j *Job) OneOff() bool

OneOff returns true for one-off jobs. One-off jobs are stored with empty interval on jobs table.

func (*Job) String

func (j *Job) String() string

String returns the job in human-readable form.

type JobJSON

type JobJSON struct {
	Path       string  `json:"path"`
	Body       string  `json:"body"`
	Interval   string  `json:"interval"`
	Location   string  `json:"location"`
	NextRun    *string `json:"next_run"`
	NextSched  string  `json:"next_sched"`
	InstanceID *uint32 `json:"instance_id"`
}

type Key

type Key struct {
	// Path is where the job is going to be POSTed when it's time came.
	Path string
	// Body of POST request.
	Body string
}

type Table

type Table struct {
	SkipLocked     bool
	FixedIntervals bool
	Clk            *clock.Clock
	// contains filtered or unexported fields
}

func New

func New(db *sql.DB, name string) *Table

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) Count

func (t *Table) Count(ctx context.Context) (int64, error)

Count returns the count of scheduled jobs in the table.

func (*Table) Create

func (t *Table) Create(ctx context.Context) error

Create jobs table.

func (*Table) DeleteInstance

func (t *Table) DeleteInstance(ctx context.Context, id uint32) error

DeleteInstance removes an entry from the list of active instances.

func (*Table) DeleteJob

func (t *Table) DeleteJob(ctx context.Context, key Key) error

DeleteJob removes a job from scheduler table.

func (*Table) DisableJob

func (t *Table) DisableJob(ctx context.Context, key Key) (*Job, error)

DisableJob prevents a job from running by setting next_run to NULL, while preserving the value of next_sched.

func (*Table) Drop

func (t *Table) Drop(ctx context.Context) error

func (*Table) EnableJob

func (t *Table) EnableJob(ctx context.Context, key Key) (*Job, error)

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

func (t *Table) Front(ctx context.Context, instanceID uint32) (*Job, error)

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) Get

func (t *Table) Get(ctx context.Context, path, body string) (*Job, error)

Get returns a job from the scheduler table, whether or not it is disabled.

func (*Table) Instances

func (t *Table) Instances(ctx context.Context) (int64, error)

Instances returns the count of running Dalga instances.

func (*Table) Lag

func (t *Table) Lag(ctx context.Context) (int64, error)

Lag returns the number of seconds passed from the execution time of the oldest pending job.

func (*Table) Pending

func (t *Table) Pending(ctx context.Context) (int64, error)

Pending returns the count of pending jobs in the table.

func (*Table) Running

func (t *Table) Running(ctx context.Context) (int64, error)

Running returns the count of total running jobs in the table.

func (*Table) UpdateInstance

func (t *Table) UpdateInstance(ctx context.Context, id uint32) error

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

func (t *Table) UpdateInstanceID(ctx context.Context, key Key, instanceID uint32) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL