task

package
v0.0.0-...-0cfeaeb Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Cron = "cron"
	Once = "once"
)

Variables

View Source
var ProviderSet = wire.NewSet(NewTaskServer)

ProviderSet is service providers.

Functions

This section is empty.

Types

type Job

type Job func()

type Task

type Task struct {
	Name string
	Type string
	// 有两种写法
	// 第一种: "@every 1h2m30s" 只能写到h, m, s
	// 第二种: cron表达式: "* 1 * * *"
	// 第三种: 只用于单次执行任务, 例如"4s", 代表任务添加后4s执行 只能写h, m, s
	Schedule string
	NextTime time.Time
	Handler  Job
}

Task represents a scheduled task

func NewTasks

func NewTasks(c *conf.Server_TASK, jobs []Job) []*Task

func (*Task) Run

func (t *Task) Run()

type TaskScheduler

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

TaskScheduler represents the task scheduler

func NewScheduler

func NewScheduler(tasks []*Task) *TaskScheduler

NewScheduler creates a new taskScheduler instance

func (*TaskScheduler) AddTask

func (s *TaskScheduler) AddTask(task Task)

AddTask adds a new task to the scheduler

func (*TaskScheduler) Start

func (s *TaskScheduler) Start()

Start starts the scheduler

func (*TaskScheduler) Stop

func (s *TaskScheduler) Stop()

Stop stops the scheduler

type TaskServer

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

func NewTaskServer

func NewTaskServer(s *service.UserXService, c *conf.Server) *TaskServer

注入对应service

func (*TaskServer) NewJobs

func (t *TaskServer) NewJobs() []Job

添加Job方法

func (*TaskServer) Start

func (t *TaskServer) Start(ctx context.Context) error

func (*TaskServer) Stop

func (t *TaskServer) Stop(ctx context.Context) error

Jump to

Keyboard shortcuts

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