yecron

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

README

yecron

介绍

{yecron 定时任务功能}

安装教程

go get gitee.com/1994net/yecron

使用说明
    
    func Job1() {
      fmt.Println("测试任务1")
    }
    
    func Job2() {
      //time.Sleep(5 * time.Second)
      fmt.Println("测试任务2")
    }
    
    func main() {
      // 创建一个定时任务对象
      cd := cron_line.CronDis()
    
      uuid := utils.GetUUID()
      jobid1 := utils.Sha1Code(utils.AddStr(uuid, "测试任务1"))
      
      cd.AddCron(Job1, "测试任务1", "0/3 * * * * * *", 0, jobid1)
      // 启用定时任务功能
      cd.Start()
    
      uuid = utils.GetUUID()
      jobid2 := utils.Sha1Code(utils.AddStr(uuid, "测试任务2"))
      AddCron(Job2, "测试任务2", "0/5 * * * * * *", 0, jobid2)

      time.Sleep(10 * time.Second)
      fmt.Println("sleep 结束")
      // 停用任务 jobid1
      cd.Stop(jobid1)
      time.Sleep(10 * time.Second)
      // 启用一个定时任务 jobid1
      cd.StartCron(jobid1)
      time.Sleep(10 * time.Second)
      // 停用所有定时任务,关闭功能
      cd.StopAll()
    }

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CronDs

type CronDs struct {
	CDs CronIntf // 定时任务实例
	// contains filtered or unexported fields
}

func New

func New(Log log.Logger) *CronDs

type CronIntf added in v0.0.3

type CronIntf interface {
	// AddCron
	// 添加任务
	AddCron(job Job)

	// RunCron
	// 启动任务
	RunCron(jobid string)

	// StopCron
	// 停止任务
	StopCron(jobid string)

	// ClearCron
	// 删除任务, 通过传入的任务ID
	ClearCron(jobid string)

	// Clear
	// 删除所有任务
	Clear()

	// Stop
	// 停止所有任务
	Stop()

	// Start
	// 启动服务
	Start()

	// GetJob
	// 获取一个定时任务
	GetJob(jobId string) Job

	// RunCount
	// 当前在运行的任务个数
	RunCount() int

	// RunCountForId
	// 定时任务的执行次数
	RunCountForId(jobId string) int
}

CronIntf 定时任务接口 jobid 通过UUID 和 任务名称 SHA1 哈希之后生成的字符串

type CronJob added in v0.0.5

type CronJob struct {
	cron_line.CronDispatch
}

func CronDis added in v0.0.5

func CronDis() (c *CronJob)

func (*CronJob) AddCron added in v0.0.5

func (cj *CronJob) AddCron(job Job)

func (*CronJob) GetJob added in v0.1.0

func (cj *CronJob) GetJob(jobId string) Job

func (*CronJob) RunCountForId added in v0.1.0

func (cj *CronJob) RunCountForId(jobId string) int

type Job

type Job struct {
	Name    string            // 任务名称
	JobId   string            // 任务ID
	Expr    string            // 解析表达式
	Status  int               // 状态
	Script  string            // 脚本
	JobFunc cron_line.JobFunc // 任务方法
}

Directories

Path Synopsis
pkg
global
* @Author: your name * @Date: 2021-10-22 10:09:08 * @LastEditTime: 2021-10-22 11:45:49 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: \issueyeCron\pkg\global\global.go
* @Author: your name * @Date: 2021-10-22 10:09:08 * @LastEditTime: 2021-10-22 11:45:49 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: \issueyeCron\pkg\global\global.go
log
service
* @Author: your name * @Date: 2021-10-22 10:09:08 * @LastEditTime: 2021-10-22 17:42:11 * @LastEditors: your name * @Description: In User Settings Edit * @FilePath: \yecron\pkg\service\cron.go
* @Author: your name * @Date: 2021-10-22 10:09:08 * @LastEditTime: 2021-10-22 17:42:11 * @LastEditors: your name * @Description: In User Settings Edit * @FilePath: \yecron\pkg\service\cron.go
sqlserver
* @Author: your name * @Date: 2021-10-22 10:09:08 * @LastEditTime: 2021-10-22 17:42:34 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: \issueyeCron\pkg\sqlserver\SqlServer.go
* @Author: your name * @Date: 2021-10-22 10:09:08 * @LastEditTime: 2021-10-22 17:42:34 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: \issueyeCron\pkg\sqlserver\SqlServer.go
utils
* @Author: your name * @Date: 2021-10-22 10:09:08 * @LastEditTime: 2021-10-22 13:18:40 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: \yecron\pkg\utils\utils.go
* @Author: your name * @Date: 2021-10-22 10:09:08 * @LastEditTime: 2021-10-22 13:18:40 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: \yecron\pkg\utils\utils.go

Jump to

Keyboard shortcuts

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