task

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateStopped int32 = iota // 0
	StateRunning              // 1
	StateClosed               // 2
)

定义状态常量

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	LoggingEnabled bool                      // 是否启用日志记录
	Interval       time.Duration             // 任务执行间隔
	Timeout        time.Duration             // 单次任务的超时时间
	TaskFunc       func(ctx context.Context) // 任务函数
}

Config 定义了任务的基础配置。

type Task added in v0.6.3

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

Task 结构体包含任务的配置和状态。

func NewTask

func NewTask(config Config) (*Task, error)

NewTask 创建并返回一个新的Task对象。 验证配置参数并初始化Task对象。

func (*Task) Close added in v0.6.3

func (t *Task) Close() error

Close 完全关闭Task,防止再次启动。 停止任务并设置关闭标志

func (*Task) Restart added in v0.6.6

func (t *Task) Restart() error

Restart 重新启动Task。 先停止任务(如果正在运行),然后再次启动。

func (*Task) Start added in v0.6.3

func (t *Task) Start() error

Start 开始执行Task中定义的任务。 锁定操作防止并发启动,并设置上下文。

func (*Task) Stop added in v0.6.3

func (t *Task) Stop() error

Stop 停止Task。 如果任务正在运行,则取消它并等待它完成。

Jump to

Keyboard shortcuts

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