scheduler

package
v2.0.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const Name = "scheduler"

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Timeout    string      `yaml:"timeout"`
	JobConfigs []JobConfig `yaml:"jobs"`
}

type CronJob

type CronJob struct {
	Expr string
}

type Job

type Job struct {
	Spec     *JobSpec
	Metadata JobMetadata
	Status   Status

	PreExecTime int64
	ExecTime    int64

	Error  error
	Result []byte
	Runs   uint64
}

type JobConfig

type JobConfig struct {
	Disabled *bool          `yaml:"disabled"`
	Name     string         `yaml:"name"`
	Timeout  *time.Duration `yaml:"timeout"`

	// MaxRetries is the maximum number of retries before aborting the
	// current job execution.
	// Default: 0.
	MaxRetries *int `yaml:"max_retries"`

	// RetryInterval is the fixed time interval between retry attempts.
	// Default: 1 second.
	RetryInterval *time.Duration `yaml:"retry_interval"`

	// Replace indicates whether the job should replace an existing job
	// with the same key.
	// Default: false.
	Replace *bool `yaml:"replace"`

	Location *string `yaml:"location"`
	// contains filtered or unexported fields
}

func (JobConfig) ToJobDetailOptions

func (c JobConfig) ToJobDetailOptions() *quartz.JobDetailOptions

type JobExecutor

type JobExecutor interface {
	Name() string
	Exec(ctx context.Context, name string, metadata *JobMetadata) result.Result[[]byte]
}

type JobFunc

type JobFunc func(ctx context.Context, name string, metadata *JobMetadata) result.Result[[]byte]

func (JobFunc) Exec

func (j JobFunc) Exec(ctx context.Context, name string, metadata *JobMetadata) result.Result[[]byte]

func (JobFunc) Name

func (j JobFunc) Name() string

type JobManager

type JobManager interface {
	CreateJob(spec JobSpec) result.Error
	PatchJob(name string, config *JobConfig) result.Error
	PauseJob(name string) result.Error
	ResumeJob(name string) result.Error
	DeleteJob(name string) result.Error
	ReloadJob(name string) result.Error
	ListJobs() []*Job
	GetJob(name string) result.Result[*Job]
}

type JobMetadata

type JobMetadata struct {
	Name          string
	Timeout       time.Duration
	MaxRetries    int
	RetryInterval time.Duration
	Replace       bool
	Location      string

	NextExecTime int64
	ExecTime     int64
}

type JobRegister

type JobRegister interface {
	RegisterSchedulerJob(reg JobRegistry)
}

type JobRegistry

type JobRegistry interface {
	Once(name string, delay time.Duration, fn JobFunc) result.Error
	Every(name string, dur time.Duration, fn JobFunc) result.Error
	Cron(name, expr string, fn JobFunc) result.Error
}

type JobSpec

type JobSpec struct {
	Name     string
	Config   *JobConfig
	Executor string
	Once     *OnceJob
	Ticker   *TickerJob
	Cron     *CronJob
}

type JobsConfigLoader

type JobsConfigLoader struct {
	Scheduler *Config `yaml:"scheduler"`
}

type OnceJob

type OnceJob struct {
	Delay time.Duration
}

type Params

type Params struct {
	M         lifecycle.Lifecycle
	Log       log.Logger
	Configs   []*Config
	Routers   []JobRegister
	Metric    metrics.Metric
	Executors []JobExecutor
}

type ResponseParams

type ResponseParams struct {
	Service supervisor.Service
	Manager JobManager
}

type Scheduler

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

func New

func New(m lifecycle.Lifecycle, logger log.Logger, metric metrics.Metric, configs []*Config, routers []JobRegister, executors []JobExecutor) (_ *Scheduler, gErr error)

func (*Scheduler) CreateJob

func (s *Scheduler) CreateJob(spec JobSpec) (r result.Error)

func (*Scheduler) Cron

func (s *Scheduler) Cron(name, expr string, fn JobFunc) result.Error

func (*Scheduler) DeleteJob

func (s *Scheduler) DeleteJob(name string) (r result.Error)

func (*Scheduler) Every

func (s *Scheduler) Every(name string, dur time.Duration, fn JobFunc) result.Error

func (*Scheduler) GetJob

func (s *Scheduler) GetJob(name string) (r result.Result[*Job])

func (*Scheduler) ListJobs

func (s *Scheduler) ListJobs() []*Job

func (*Scheduler) Once

func (s *Scheduler) Once(name string, delay time.Duration, fn JobFunc) result.Error

func (*Scheduler) PatchJob

func (s *Scheduler) PatchJob(name string, config *JobConfig) (r result.Error)

func (*Scheduler) PauseJob

func (s *Scheduler) PauseJob(name string) (r result.Error)

func (*Scheduler) ReloadJob

func (s *Scheduler) ReloadJob(name string) (r result.Error)

func (*Scheduler) ResumeJob

func (s *Scheduler) ResumeJob(name string) (r result.Error)

func (*Scheduler) Serve

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

func (*Scheduler) String

func (s *Scheduler) String() string

type Status

type Status string
const (
	StatusRunning Status = "running"
	StatusStop    Status = "stop"
)

type TickerJob

type TickerJob struct {
	Dur time.Duration
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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