store

package
v3.0.1-0...-a732d86 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("job not found")
)

Functions

This section is empty.

Types

type Entry

type Entry struct {
	// ID is the cron-assigned ID of this entry, which may be used to look up a
	// snapshot or remove it.
	ID EntryID

	Type EntryType

	Status EntryStatus

	// Schedule is the string representation of job schedule
	Schedule schedule.Schedule

	// Next time the job will run, or the zero time if Cron has not been
	// started or this entry's schedule is unsatisfiable
	Next int64

	// Prev is the last time this job was run, or the zero time if never.
	Prev int64

	// Payload is a raw representation of job context
	Payload []byte
}

Entry contains general information about the job

func (Entry) Valid

func (e Entry) Valid() bool

Valid returns true if this is not the zero entry.

type EntryID

type EntryID string

EntryID identifies an entry within a Cron instance

type EntryStatus

type EntryStatus int
const (
	Scheduled EntryStatus = iota
	Active
	Succeeded
	Failed
)

type EntryType

type EntryType string

EntryType defines job which should be run

type JobSetter

type JobSetter func(*Entry)

EntrySetter changes values of Entry fields

func SetNext

func SetNext(next time.Time) JobSetter

SetNext sets value of the Entry's Next field

func SetPayload

func SetPayload(payload []byte) JobSetter

func SetPrev

func SetPrev(prev time.Time) JobSetter

SetPrev sets value of the Entry's Prev field

func SetSchedule

func SetSchedule(s schedule.Schedule) JobSetter

func SetStatus

func SetStatus(s EntryStatus) JobSetter

type Store

type Store interface {
	// Register appends the Entry to the set of scheduled jobs
	Register(Entry) error

	// Entry returns Entry by EntryID or empty value
	// if such job doesn't registered
	Entry(EntryID, schedule.Parser) (Entry, error)

	// Update modifies the job by applying EntrySetters to the instance
	Update(EntryID, schedule.Parser, ...JobSetter) error

	// Remove removes the Entry from the set of scheduled jobs
	Remove(EntryID) error

	// Snapshot returns a snapshot of the set of scheduled jobs
	Snapshot(schedule.Parser) ([]Entry, error)

	// Next returns EntryID and start time of the soonest job
	Next() (EntryID, time.Time, error)

	// Ready returns slice of entries which are
	// ready to start at the particular time
	Ready(time.Time, schedule.Parser) ([]Entry, error)
}

Store encapsulates a logic of interaction with scheduled jobs. Cron assumes exclusive store possession, so you shouldn't use it directly while cron is running to prevent unexpected behaviour.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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