gojob

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

README

定时任务

 需要支持荥
 带参数的任务函数 定时执行还没支持
 每个月某一天几点执行

package main

import (
	gojob "github.com/gif-gif/go.io/go-job"
	golog "github.com/gif-gif/go.io/go-log"
	"time"
)

func main() {
	DataChan := make(chan []byte, 20)

	n := 1
	cron, err := gojob.New()
	if err != nil {
		golog.WithTag("gojob").Error(err)
	}
	defer cron.Stop()
	defer close(DataChan)

	cron.Start()
	cron.Second(func() {
		if r := recover(); r != nil {
			golog.Error(r)
		}

		golog.WithTag("gojob").Info("testing")
		n++
		if n > 5 {
			n = 0
			cron.Stop()
		}
		DataChan <- []byte("json")
	})

	go func() {
		for {
			select {
			case data := <-DataChan:
				golog.WithTag("gojob").Info(string(data))
			}
		}
	}()

	time.Sleep(time.Second * 5)

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CronsModel

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

func New

func New() (*CronsModel, error)

func (*CronsModel) Cron

func (o *CronsModel) Cron() gocron.Scheduler

func (*CronsModel) CronJob added in v1.1.2

func (c *CronsModel) CronJob(spec string, fn ...func())

spec is crontab pattern crontab 表达式

func (*CronsModel) DailyJob added in v1.1.2

func (c *CronsModel) DailyJob(interval uint, hours []uint, minute uint, fn ...func())

每天定时执行

func (*CronsModel) Day

func (c *CronsModel) Day(fn ...func())

crontab 每天0点0分0秒执行

func (*CronsModel) DayHour

func (c *CronsModel) DayHour(hour int, fn ...func())

crontab 每天x点0分0秒执行

func (*CronsModel) DayHourMinute

func (c *CronsModel) DayHourMinute(hour, minute int, fn ...func())

crontab 每天x点x分0秒执行

func (*CronsModel) DurationJob added in v1.1.2

func (c *CronsModel) DurationJob(seconds int, fn ...func())

隔多少秒执行

func (*CronsModel) DurationRandomJob added in v1.1.2

func (c *CronsModel) DurationRandomJob(minDuration, maxDuration time.Duration, fn ...func())

DurationRandomJob 定义一个新作业,该作业以提供的最小和最大持续时间值之间的随机间隔运行

func (*CronsModel) Hour

func (c *CronsModel) Hour(fn ...func())

crontab 每小时执行

func (*CronsModel) HourX

func (c *CronsModel) HourX(x int, fn ...func())

crontab 每隔x小时执行

func (*CronsModel) Minute

func (c *CronsModel) Minute(fn ...func())

crontab 每分钟执行

func (*CronsModel) MinuteX

func (c *CronsModel) MinuteX(x int, fn ...func())

crontab 每隔x分钟执行

func (*CronsModel) MonthlyJob added in v1.1.2

func (c *CronsModel) MonthlyJob(interval uint, daysOfTheMonth []int, hours []uint, minutes uint, fn ...func())

interval 月频, 0-6-->周日 周一 ... 周六, hours 具体执行时间列表

func (*CronsModel) OneTimeJobForMinute added in v1.1.2

func (c *CronsModel) OneTimeJobForMinute(minute uint, fn ...func())

当前时间 minute 分钟之后执行一次

func (*CronsModel) OneTimeJobForSeconds added in v1.1.2

func (c *CronsModel) OneTimeJobForSeconds(seconds uint, fn ...func())

当前时间 seconds 秒之后执行一次

func (*CronsModel) Second

func (c *CronsModel) Second(fn ...func())

crontab 每秒钟执行

func (*CronsModel) SecondX

func (c *CronsModel) SecondX(x int, fn ...func())

crontab 每隔x秒执行

func (*CronsModel) Start

func (c *CronsModel) Start()

func (*CronsModel) Stop

func (c *CronsModel) Stop() error

func (*CronsModel) WeeklyJob added in v1.1.2

func (c *CronsModel) WeeklyJob(interval uint, daysOfTheWeek []time.Weekday, hours []uint, minutes uint, fn ...func())

interval 周频, 0-6-->周日 周一 ... 周六, hours 具体执行时间列表

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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