job

package
v0.0.0-...-f664ad0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartCronJob

func StartCronJob(c *cron.Cron, jobBuilder CronJobBuilder, schedule string) (cron.EntryID, error)

StartCronJob 启动定时任务

Types

type CronJobBuilder

type CronJobBuilder interface {
	Name() string
	Run() error
	Build() cron.Job
}

func NewCronJobBuilder

func NewCronJobBuilder(name string, run func() error, l *zap.Logger) CronJobBuilder

type Executor

type Executor interface {
	Name() string
	Exec(ctx context.Context, dj domain.Job) error
	RegisterFunc(name string, fn func(ctx context.Context, dj domain.Job) error)
}

Executor 定义了任务执行器接口

func NewLocalFuncExecutor

func NewLocalFuncExecutor() Executor

NewLocalFuncExecutor 创建并初始化 LocalFuncExecutor 实例

type LocalFuncExecutor

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

LocalFuncExecutor 本地方法执行器

func (*LocalFuncExecutor) Exec

func (l *LocalFuncExecutor) Exec(ctx context.Context, dj domain.Job) error

Exec 执行注册的本地方法

func (*LocalFuncExecutor) Name

func (l *LocalFuncExecutor) Name() string

Name 返回执行器名称

func (*LocalFuncExecutor) RegisterFunc

func (l *LocalFuncExecutor) RegisterFunc(name string, fn func(ctx context.Context, dj domain.Job) error)

RegisterFunc 注册本地执行函数

type Scheduler

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

func NewScheduler

func NewScheduler(svc service.CronJobService, l *zap.Logger) *Scheduler

func (*Scheduler) RegisterExecutor

func (s *Scheduler) RegisterExecutor(exec Executor)

RegisterExecutor 注册任务执行器

func (*Scheduler) Schedule

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

Schedule 调度任务执行

Jump to

Keyboard shortcuts

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