zcrontab

package module
v0.0.0-...-29bfd29 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2019 License: MIT Imports: 5 Imported by: 0

README

ZCrontab

zcrontab is a crontab、at task processor based on golang:

  • based on time.ticker,no need of crond service

  • support task deletion and callback

  • crontab

    • the crontab task support all crontab symbol including *,-,/,,
  • at

    • the at task can be repeated at the same time(every day)

Usage

Install

glide get github.com/zzerroo/zcrontab

example

import (
	"fmt"
	"time"
	"ztimer/zcrontab"
)

func test(args interface{}) {
	fmt.Println(args)
}
 
func main() {
	zCrontab := zcrontab.NewZCrontab()
	zCrontab.Crontab("* * * * *", test, "*")
	zCrontab.Crontab("*/2 * * * *", test, "every 2 minute")
	zCrontab.Crontab("* 15 * * *", test, "every minute 3")
	zCrontab.Crontab("*/2 15,16 * * *", test, "every 2 minute 3,4")
	zCrontab.Crontab("*/2 15-16 * * *", test, "every 2 minute 3-4")
	zCrontab.Crontab("* 15-16/2 * * *", test, "every minute 3-4/3")
	zCrontab.At(time.Now().Add(1*time.Minute), test, "this is test for at repeat", true)
	zCrontab.At(time.Now().Add(1*time.Minute), test, "this is test for at", false)
	select {}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ZCrontab

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

func NewZCrontab

func NewZCrontab() *ZCrontab

NewZCrontab ...

func (*ZCrontab) At

func (z *ZCrontab) At(t time.Time, f func(interface{}), args interface{}, repeated bool) (string, error)

At add a at task, t is the task time, f and args is the callback and input, repeat indicate wheather the task will repeat every day(will ignore the date info)

func (*ZCrontab) Crontab

func (z *ZCrontab) Crontab(cronStr string, f func(interface{}), args interface{}) (string, error)

Crontab add a crontab task,cronStr is a crontab string,f and args is the callback and input

func (*ZCrontab) RmAt

func (z *ZCrontab) RmAt(id string)

RmAt remove the task

Jump to

Keyboard shortcuts

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