cron

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2016 License: MIT Imports: 5 Imported by: 0

README

go cron

golang cron like service

Supported system

Linux
Windows 8
Windows 7
Windows XP
OS X

Features

┌───────────── sec (0 - 59)
│ ┌───────────── min (0 - 59)
│ │ ┌────────────── hour (0 - 23)
│ │ │ ┌─────────────── day of month (1 - 31)
│ │ │ │ ┌──────────────── month (1 - 12)
│ │ │ │ │ ┌───────────────── day of week (0 - 6)
│ │ │ │ │ │                                         
│ │ │ │ │ │
│ │ │ │ │ │
* * * * * *  

Clone

    git clone https://github.com/e154/cron.git /path/to/clone   

init

    go get github.com/e154/cron   

    import (
        "time"
        "strings"
        "strconv"
        c "github.com/e154/cron"
    )
    
    cron := c.NewCron()
    
    cron.NewTask("* * * * * *", func(){log.Println("task1")})
    cron.NewTask("10,44 * * * * *", func(){log.Println("task2")})
    cron.NewTask("5 * * * * *", func(){log.Println("task3")})
    //cron.NewTask("*/5 * * * * *", func(){log.Println("task4")})	// not supported
    cron.NewTask("1-45,47,50 * * * * *", func(){log.Println("task5")})
    cron.NewTask("45-59,20 * * * * *", func(){log.Println("task6")})
    cron.NewTask("0 23 * * * *", func(){log.Println("task7")})
    cron.NewTask("* 24 16 * * *", func(){log.Println("task8")})
    cron.NewTask("0 24 16 * * *", func(){log.Println("task9")})

    cron.Run()

    for {
        time.Sleep(time.Second)
    }
LICENSE

go cron is licensed under the MIT License (MIT)

Documentation

Index

Constants

View Source
const (
	SECOND int = iota
	MINUTE
	HOUR
	DAY
	MONTH
	WEEKDAY
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cron

type Cron struct {
	StartTime time.Time
	Uptime    time.Duration
	// contains filtered or unexported fields
}

func NewCron

func NewCron() *Cron

func (*Cron) NewTask

func (c *Cron) NewTask(t string, h func()) *Task

func (*Cron) RemoveTask

func (c *Cron) RemoveTask(task *Task)

func (*Cron) Run

func (c *Cron) Run() *Cron

func (*Cron) Stop

func (c *Cron) Stop() *Cron

type Task

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

func (*Task) Disable

func (t *Task) Disable() *Task

func (*Task) Enable

func (t *Task) Enable() *Task

func (*Task) Enabled

func (t *Task) Enabled() bool

func (*Task) GetTime

func (t *Task) GetTime() (time string)

func (*Task) Run

func (t *Task) Run()

func (*Task) SetTime

func (t *Task) SetTime(time string)

Jump to

Keyboard shortcuts

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