jobs

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyJobKey  = errors.New("empty job key")
	ErrEmptyJobType = errors.New("empty job type")
)
View Source
var (
	ErrInvalidCronSpec = "invalid cron spec: %v"
)
View Source
var (
	ErrPastTime = errors.New("time before now")
)

Functions

This section is empty.

Types

type BaseJob

type BaseJob struct {
	JKey  string
	JType string
}

func NewBaseJob

func NewBaseJob(jType, key string) (BaseJob, error)

func (*BaseJob) Key

func (j *BaseJob) Key() string

func (*BaseJob) Type

func (j *BaseJob) Type() string

type CronJob

type CronJob struct {
	BaseJob
	Data     interface{}
	CronSpec string
	// contains filtered or unexported fields
}

func NewCronJob

func NewCronJob(jType, key string, cronSpec string, data interface{}) (*CronJob, error)

data is optional and may be nil

func (*CronJob) Marshal

func (j *CronJob) Marshal() ([]byte, error)

func (*CronJob) NextTriggerTime

func (j *CronJob) NextTriggerTime() time.Time

func (*CronJob) PostExecution

func (j *CronJob) PostExecution(_ time.Time, _ error)

func (*CronJob) Unmarshal

func (j *CronJob) Unmarshal(b []byte) error

type Job

type Job interface {
	Key() string
	Type() string

	// Should return Time.IsZero() when job is done.
	NextTriggerTime() time.Time
	// Used to count executions and post-processing.
	PostExecution(time.Time, error)

	Marshaler
	Unmarshaler
}

type Marshaler

type Marshaler interface {
	Marshal() ([]byte, error)
}

Marshaler is the interface implemented by types that can marshal themselves.

type OneTimeJob

type OneTimeJob struct {
	BaseJob
	Data        interface{}
	TriggerTime time.Time
	Executed    bool
}

func NewOneTimeJob

func NewOneTimeJob(jType, key string, triggerTime time.Time, data interface{}) (*OneTimeJob, error)

data is optional and may be nil

func (*OneTimeJob) Marshal

func (j *OneTimeJob) Marshal() ([]byte, error)

func (*OneTimeJob) NextTriggerTime

func (j *OneTimeJob) NextTriggerTime() time.Time

func (*OneTimeJob) PostExecution

func (j *OneTimeJob) PostExecution(_ time.Time, err error)

func (*OneTimeJob) Unmarshal

func (j *OneTimeJob) Unmarshal(b []byte) error

type State

type State uint32
const (
	StateScheduled State
	StateUnacquired
	StateExhausted
)

func (State) String

func (s State) String() string

type Unmarshaler

type Unmarshaler interface {
	Unmarshal([]byte) error
}

Unmarshaler is the interface implemented by types that can unmarshal a byte description of themselves.

Jump to

Keyboard shortcuts

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