scheduler

package
v0.0.0-...-58b8290 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job interface {
	// ID returns the Job unique identifier
	ID() string
	// Run execute the job
	Run(ctx context.Context) error
}

Job will be implemented by any job runner

type JobsScheduler

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

JobsScheduler implements Scheduler

func NewJobsScheduler

func NewJobsScheduler() *JobsScheduler

NewJobsScheduler creates a new instance of Scheduler. It accepts for cronExpression

  • Standard crontab specs, e.g. "* * * * ?"
  • With optional second field, e.g. "* * * * * ?"
  • Descriptors, e.g. "@midnight", "@every 1h30m"

func (*JobsScheduler) AddJob

func (s *JobsScheduler) AddJob(ctx context.Context, cronExpression string, job Job) error

AddJob adds new Job to the scheduler. If the job already exists rejects the request.

func (*JobsScheduler) Run

func (s *JobsScheduler) Run(ctx context.Context)

Run runs the scheduler by executing all jobs that have been added to it.

func (*JobsScheduler) Start

func (s *JobsScheduler) Start(ctx context.Context)

Start starts the scheduler and run all the jobs in their separate go-routine

func (*JobsScheduler) Stop

func (s *JobsScheduler) Stop(ctx context.Context) error

Stop shutdowns the Scheduler gracefully

type Scheduler

type Scheduler interface {
	// Start starts the scheduler and run all the jobs in their separate go-routine
	Start(ctx context.Context)
	// Stop stops the scheduler and stop any running job
	Stop(ctx context.Context) error
	// Run runs the scheduler by executing all jobs that have been added to it.
	Run(ctx context.Context)
	// AddJob add a new job runner to the scheduler. The jobID and cronExpression is required.
	// It accepts for cronExpression
	//   - Standard crontab specs, e.g. "* * * * ?"
	//   - With optional second field, e.g. "* * * * * ?"
	//   - Descriptors, e.g. "@midnight", "@every 1h30m"
	AddJob(ctx context.Context, cronExpression string, job Job) error
}

Scheduler will be implemented by the scheduler

Jump to

Keyboard shortcuts

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