gojob

package
v1.0.20 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

README

定时任务

package main

import (
	gocrons "github.com/gif-gif/go.io/go-cron"
	golog "github.com/gif-gif/go.io/go-log"
	"time"
)

func main() {
	DataChan := make(chan []byte, 20)
	n := 1
	cron := gocrons.New()
	cron.Start() //启动
	cron.Second(func() {
		if r := recover(); r != nil {
			golog.Error(r)
		}

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

	go func() {
		for {
			select {
			case data := <-DataChan:
				golog.WithTag("gocrons").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) Day

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

每天0点0分0秒执行

func (*CronsModel) DayHour

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

每天x点0分0秒执行

func (*CronsModel) DayHourMinute

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

每天x点x分0秒执行

func (*CronsModel) Func

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

func (*CronsModel) Hour

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

每小时执行

func (*CronsModel) HourX

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

每隔x小时执行

func (*CronsModel) Minute

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

每分钟执行

func (*CronsModel) MinuteX

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

每隔x分钟执行

func (*CronsModel) Second

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

每秒钟执行

func (*CronsModel) SecondX

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

每隔x秒执行

func (*CronsModel) Start

func (c *CronsModel) Start()

func (*CronsModel) Stop

func (c *CronsModel) Stop() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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