scheduler

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

scheduler/options.go

scheduler/task.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job func(ctx context.Context) error

Job 定义任务函数

type JobResult

type JobResult struct {
	Name     string
	Duration time.Duration
	Success  bool
	Err      error
}

JobResult 用于记录任务执行结果

type Task

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

Task 表示一个可配置的任务

func NewTask

func NewTask(opts ...TaskOption) *Task

NewTask 创建新任务,并应用所有配置项

func (*Task) Run

func (t *Task) Run()

Run 启动任务

func (*Task) Stop

func (t *Task) Stop()

Stop 停止任务

type TaskOption

type TaskOption func(*Task)

TaskOption 是配置任务的函数类型

func WithCancelOnFailure

func WithCancelOnFailure(cancel bool) TaskOption

WithCancelOnFailure 设置失败时是否取消任务

func WithErrorHandler

func WithErrorHandler(handler func(error)) TaskOption

WithErrorHandler 设置错误处理器

func WithJob

func WithJob(job func(context.Context) error) TaskOption

WithJob 设置任务主体函数

func WithLogger

func WithLogger(logger func(string, ...any)) TaskOption

WithLogger 自定义日志记录器

func WithMaxRuns

func WithMaxRuns(n int) TaskOption

WithMaxRuns 设置最大运行次数

func WithMetricCollector

func WithMetricCollector(collector func(JobResult)) TaskOption

WithMetricCollector 收集任务指标

func WithName

func WithName(name string) TaskOption

WithName 设置任务名称

func WithParallelism

func WithParallelism(n int) TaskOption

WithParallelism 并发执行多个任务(暂不实现并发控制,仅保留字段)

func WithPostHook

func WithPostHook(hook func()) TaskOption

WithPostHook 添加执行后钩子

func WithPreHook

func WithPreHook(hook func()) TaskOption

WithPreHook 添加执行前钩子

func WithRecover

func WithRecover(hook func(interface{})) TaskOption

WithRecover 添加 panic 恢复钩子

func WithRepeat

func WithRepeat(interval time.Duration) TaskOption

WithRepeat 设置任务以固定间隔重复执行

func WithRetry

func WithRetry(n int) TaskOption

WithRetry 出错重试 n 次

func WithStartupDelay

func WithStartupDelay(delay time.Duration) TaskOption

WithStartupDelay 设置延迟启动时间

func WithTimeout

func WithTimeout(timeout time.Duration) TaskOption

WithTimeout 设置任务超时时间

Jump to

Keyboard shortcuts

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