schedule

package
v0.17.6 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0, MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InvalidJobID = JobID(0)

Functions

This section is empty.

Types

type Job

type Job interface {
	// Run starts running the task and blocks until the context is done or
	// an error occurs. Run may be called again after an error or timeout to
	// retry the job so implemententions must ensure that Run resets any
	// necessary state.
	Run(context.Context) error
	Done() <-chan struct{}
}

type JobConfig

type JobConfig struct {

	// Reporter is a job report
	Reporter *Reporter

	// Name is a human readable name for the job for use in logging
	Name string

	// Tasks is a list of tasks the job performs
	Tasks []string

	// Job is the job that will be executed.
	Job Job

	// Locker is an optional lock that must be taken before the job can execute.
	Locker Locker

	// RestartOnFailure controls whether the job should be restarted if it stops with an error.
	RestartOnFailure bool

	// RestartOnCompletion controls whether the job should be restarted if it stops without an error.
	RestartOnCompletion bool

	// RestartDelay is the amount of time to wait before restarting a stopped job
	RestartDelay time.Duration

	// Type is a human readable type for the job for use in logging.
	Type string

	// Params is a map of additional parameters that add human readable context to the job.
	Params map[string]string

	// StartedAt is the time the job started running.
	StartedAt time.Time

	// EndedAt is the time the job stopped running, either through successful completion or failure. Reset if job is restarted.
	EndedAt time.Time
	// contains filtered or unexported fields
}

type JobID

type JobID int

type JobListResult added in v0.8.2

type JobListResult struct {
	ID    JobID
	Name  string
	Type  string
	Error string
	Tasks []string

	Running bool

	RestartOnFailure    bool
	RestartOnCompletion bool
	RestartDelay        time.Duration

	Params    map[string]string
	StartedAt time.Time
	EndedAt   time.Time

	Report *Reporter
}

type JobSubmitResult added in v0.8.2

type JobSubmitResult struct {
	ID                  JobID
	Name                string
	Type                string
	Tasks               []string
	Params              map[string]string
	RestartOnFailure    bool
	RestartOnCompletion bool
	RestartDelay        time.Duration
}

type Locker

type Locker interface {
	Lock(context.Context) error
	Unlock(context.Context) error
}

Locker represents a general lock that a job may need to take before operating.

type Reporter added in v0.14.0

type Reporter struct {
	// Current Height is the current height of the job
	CurrentHeight int64
}

func (*Reporter) UpdateCurrentHeight added in v0.14.0

func (r *Reporter) UpdateCurrentHeight(height int64)

type Scheduler

type Scheduler struct {
	// contains filtered or unexported fields
}

func NewScheduler

func NewScheduler(jobDelay time.Duration, scheduledJobs ...*JobConfig) *Scheduler

func NewSchedulerDaemon

func NewSchedulerDaemon(mctx helpers.MetricsCtx, lc fx.Lifecycle) *Scheduler

func (*Scheduler) Jobs

func (s *Scheduler) Jobs() []JobListResult

func (*Scheduler) Run

func (s *Scheduler) Run(ctx context.Context) error

Run starts running the scheduler and blocks until the context is done.

func (*Scheduler) StartJob

func (s *Scheduler) StartJob(id JobID) error

func (*Scheduler) StopJob

func (s *Scheduler) StopJob(id JobID) error

func (*Scheduler) Submit

func (s *Scheduler) Submit(jc *JobConfig) *JobSubmitResult

func (*Scheduler) WaitJob added in v0.8.6

func (s *Scheduler) WaitJob(ctx context.Context, id JobID) (*JobListResult, error)

Jump to

Keyboard shortcuts

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