runner

package
v0.0.0-...-0d6871a Latest Latest
Warning

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

Go to latest
Published: May 13, 2022 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapForCron

func WrapForCron(r *Runner, job Job, cronID *cron.EntryID) cron.Job

Types

type Job

type Job interface {

	// Name of the job.
	Name() string

	// Run runs the job.
	// Any logging or other relevant output produced should be written to the given writer.
	Run(ctx context.Context, w io.Writer) error
}

Job represents a runnable job, typically set up to perform some side effect or interacting with sirkulator data.

type JobRun

type JobRun struct {
	ID      int64
	Name    string
	StartAt time.Time
	StopAt  time.Time
	Status  string // running|ok|failed|cancelled
	Output  string
	// The following fields are only present in active jobs (scheduled or currently running)
	CronID cron.EntryID       // id needed for removing scheduled job from cron
	Cancel context.CancelFunc // to cancel a job
	Done   chan struct{}      // if you need to wait until job is done
}

JobRun represents a run of a job that has been started. It corresponds to a row in the job_run table.

type Runner

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

Runner executes jobs, either ad-hoc or by cron-schedule.

func New

func New(db *sqlitex.Pool) *Runner

func (*Runner) DeleteSchedule

func (r *Runner) DeleteSchedule(ctx context.Context, id int64) error

func (*Runner) GetJob

func (r *Runner) GetJob(name string) (Job, bool)

func (*Runner) GetJobRun

func (r *Runner) GetJobRun(ctx context.Context, id int64) (JobRun, error)

func (*Runner) JobNames

func (r *Runner) JobNames() []string

func (*Runner) JobRuns

func (r *Runner) JobRuns(ctx context.Context, limit int) ([]JobRun, error)

func (*Runner) ParseCron

func (r *Runner) ParseCron(s string) (cron.Schedule, error)

func (*Runner) Register

func (r *Runner) Register(job Job)

Register the given job. If a Job exists with the same name, it will be overwritten

func (*Runner) RunJob

func (r *Runner) RunJob(ctx context.Context, jobName string) (int64, chan struct{}, error)

RunJob runs a job immedeatly. Returns the job run ID and a channel which will send when the job is completed. TODO return JobRun instead, align with cron scheduled jobs (running map etc)

func (*Runner) ScheduleJob

func (r *Runner) ScheduleJob(ctx context.Context, jobName string, cronExpr string) error

func (*Runner) Schedules

func (r *Runner) Schedules(ctx context.Context) ([]Schedule, error)

func (*Runner) Start

func (r *Runner) Start(ctx context.Context) error

func (*Runner) Stop

func (r *Runner) Stop() context.Context

type Schedule

type Schedule struct {
	ID   int64
	Name string
	Cron string
}

Schedule corresponds to a row in the job_schedule table.

Jump to

Keyboard shortcuts

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