cron

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentJobs

func CurrentJobs() map[string]cron.Job

CurrentJobs return the currents running jobs.

func Register

func Register(ctx context.Context, mc *model.Client, cs JobCreators) (err error)

Register executes all job creators and schedules the returning task with the returning expression.

func SetupSyncer

func SetupSyncer(ctx context.Context, opts StartSyncerOptions) error

func Sync

Sync observes the cron expr setting changes and re-register jobs.

Types

type Expr

type Expr = cron.Expr

Expr holds the definition of cron expression.

func AwaitedExpr

func AwaitedExpr(raw string) Expr

AwaitedExpr returns an Expr and runs in the next round.

func ImmediateExpr

func ImmediateExpr(raw string) Expr

ImmediateExpr returns an Expr and runs in the next round.

type JobCreator

type JobCreator func(ctx context.Context, name, expr string) (Expr, Task, error)

JobCreator is the creator for creating {cron.Expr, cron.Task} tuple, the life of given context.Context ends by this creation, do not use the long-term processing with this context.Context.

type JobCreators

type JobCreators map[string]JobCreator

JobCreators holds JobCreator with its name.

type Lock

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

Lock implement the cronjob go-co-op/gocron Lock interface.

func (*Lock) Unlock

func (l *Lock) Unlock(ctx context.Context) (err error)

Unlock release the locked key.

type Locker

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

Locker implement the cronjob go-co-op/gocron Locker interface.

func NewLocker

func NewLocker(client *model.Client, options ...Option) *Locker

NewLocker create locker with model client and options.

func (*Locker) Lock

func (l *Locker) Lock(ctx context.Context, key string) (lock cron.Lock, err error)

Lock try to lock the key provided, return error while failed to lock key.

type Option

type Option func(*Locker)

Option is a function that configures a locker.

func WithExpiryInterval

func WithExpiryInterval(expiry time.Duration) Option

WithExpiryInterval can be used to set the expiry of a locker to set to every key.

func WithRenewConfig

func WithRenewConfig(renewInterval, maxExecuteDuration time.Duration) Option

WithRenewConfig can be used to set renew interval and max execute duration of a locker.

type StartSyncerOptions

type StartSyncerOptions struct {
	ModelClient model.ClientSet
	Interval    time.Duration
}

type Syncer

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

func NewSyncer

func NewSyncer(mc model.ClientSet) *Syncer

func (*Syncer) Sync

func (in *Syncer) Sync(ctx context.Context) error

type Task

type Task = cron.Task

Task defines the interface to hold the job executing main logic.

Jump to

Keyboard shortcuts

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