timer

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2025 License: MIT Imports: 3 Imported by: 0

README

定时任务使用方法

1. 实现Jober接口,注册任务

例如:

// 注册任务
func init() {
	timer.RegisterJob(&TestTimer{})
}

// 实现Jober接口
type TestTimer struct {
}

func (t *TestTimer) GetName() string {
	return "TestTimer"
}

func (t *TestTimer) GetCron() string {
	return "*/1 * * * *"
}

func (t *TestTimer) Run() {
	log.Println("TestTimer is run")
}

2. 在入口出引入即可

例: import _ "gintpl/internal/timer"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterJob

func RegisterJob(job Jober)

RegisterJob 注册任务

func Run

func Run()

Run 启动定时器

func Stop

func Stop()

Stop 停止定时器

Types

type Jober

type Jober interface {
	cron.Job
	GetName() string
	GetCron() string
}

Jober 任务接口

Jump to

Keyboard shortcuts

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