gf: github.com/johng-cn/gf/g/os/gcron Index | Examples | Files

package gcron

import "github.com/johng-cn/gf/g/os/gcron"

Package gcron implements a cron pattern parser and job runner.

Index

Examples

Package Files

gcron.go gcron_cron.go gcron_entry.go gcron_schedule.go

Constants

const (
    STATUS_READY   = gtimer.STATUS_READY
    STATUS_RUNNING = gtimer.STATUS_RUNNING
    STATUS_STOPPED = gtimer.STATUS_STOPPED
    STATUS_CLOSED  = gtimer.STATUS_CLOSED
)

func DelayAdd Uses

func DelayAdd(delay time.Duration, pattern string, job func(), name ...string)

DelayAdd adds a timed task to default cron object after <delay> time.

func DelayAddOnce Uses

func DelayAddOnce(delay time.Duration, pattern string, job func(), name ...string)

DelayAddOnce adds a timed task after <delay> time to default cron object. This timed task can be run only once.

func DelayAddSingleton Uses

func DelayAddSingleton(delay time.Duration, pattern string, job func(), name ...string)

DelayAddSingleton adds a singleton timed task after <delay> time to default cron object.

func DelayAddTimes Uses

func DelayAddTimes(delay time.Duration, pattern string, times int, job func(), name ...string)

DelayAddTimes adds a timed task after <delay> time to default cron object. This timed task can be run specified times.

func GetLogLevel Uses

func GetLogLevel() int

GetLogLevel returns the logging level for default cron object.

func GetLogPath Uses

func GetLogPath() string

GetLogPath returns the logging folder path of default cron object.

func Remove Uses

func Remove(name string)

Remove deletes scheduled task which named <name>.

func SetLogLevel Uses

func SetLogLevel(level int)

SetLogLevel sets the logging level for default cron object.

func SetLogPath Uses

func SetLogPath(path string)

SetLogPath sets the logging folder path for default cron object.

func Size Uses

func Size() int

Size returns the size of the timed tasks of default cron.

func Start Uses

func Start(name string)

Start starts running the specified timed task named <name>.

func Stop Uses

func Stop(name string)

Stop stops running the specified timed task named <name>.

type Cron Uses

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

func New Uses

func New() *Cron

New returns a new Cron object with default settings.

func (*Cron) Add Uses

func (c *Cron) Add(pattern string, job func(), name ...string) (*Entry, error)

Add adds a timed task. A unique <name> can be bound with the timed task. It returns and error if the <name> is already used.

func (*Cron) AddOnce Uses

func (c *Cron) AddOnce(pattern string, job func(), name ...string) (*Entry, error)

AddOnce adds a timed task which can be run only once. A unique <name> can be bound with the timed task. It returns and error if the <name> is already used.

func (*Cron) AddSingleton Uses

func (c *Cron) AddSingleton(pattern string, job func(), name ...string) (*Entry, error)

AddSingleton adds a singleton timed task. A singleton timed task is that can only be running one single instance at the same time. A unique <name> can be bound with the timed task. It returns and error if the <name> is already used.

Code:

gcron.AddSingleton("* * * * * *", func() {
    glog.Println("doing")
    time.Sleep(2 * time.Second)
})
select {}

func (*Cron) AddTimes Uses

func (c *Cron) AddTimes(pattern string, times int, job func(), name ...string) (*Entry, error)

AddTimes adds a timed task which can be run specified times. A unique <name> can be bound with the timed task. It returns and error if the <name> is already used.

func (*Cron) Close Uses

func (c *Cron) Close()

Close stops and closes current cron.

func (*Cron) DelayAdd Uses

func (c *Cron) DelayAdd(delay time.Duration, pattern string, job func(), name ...string)

DelayAdd adds a timed task after <delay> time.

func (*Cron) DelayAddOnce Uses

func (c *Cron) DelayAddOnce(delay time.Duration, pattern string, job func(), name ...string)

DelayAddOnce adds a timed task after <delay> time. This timed task can be run only once.

func (*Cron) DelayAddSingleton Uses

func (c *Cron) DelayAddSingleton(delay time.Duration, pattern string, job func(), name ...string)

DelayAddSingleton adds a singleton timed task after <delay> time.

func (*Cron) DelayAddTimes Uses

func (c *Cron) DelayAddTimes(delay time.Duration, pattern string, times int, job func(), name ...string)

DelayAddTimes adds a timed task after <delay> time. This timed task can be run specified times.

func (*Cron) Entries Uses

func (c *Cron) Entries() []*Entry

Entries return all timed tasks as slice(order by registered time asc).

func (*Cron) GetLogLevel Uses

func (c *Cron) GetLogLevel() int

GetLogLevel returns the logging level.

func (*Cron) GetLogPath Uses

func (c *Cron) GetLogPath() string

GetLogPath return the logging folder path.

func (*Cron) Remove Uses

func (c *Cron) Remove(name string)

Remove deletes scheduled task which named <name>.

func (*Cron) Search Uses

func (c *Cron) Search(name string) *Entry

Search returns a scheduled task with the specified <name>. It returns nil if no found.

func (*Cron) SetLogLevel Uses

func (c *Cron) SetLogLevel(level int)

SetLogLevel sets the logging level.

func (*Cron) SetLogPath Uses

func (c *Cron) SetLogPath(path string)

SetLogPath sets the logging folder path.

func (*Cron) Size Uses

func (c *Cron) Size() int

Size returns the size of the timed tasks.

func (*Cron) Start Uses

func (c *Cron) Start(name ...string)

Start starts running the specified timed task named <name>.

func (*Cron) Stop Uses

func (c *Cron) Stop(name ...string)

Stop stops running the specified timed task named <name>.

type Entry Uses

type Entry struct {
    Name string    // Entry name.
    Job  func()    `json:"-"` // Callback function.
    Time time.Time // Registered time.
    // contains filtered or unexported fields
}

Timed task entry.

func Add Uses

func Add(pattern string, job func(), name ...string) (*Entry, error)

Add adds a timed task to default cron object. A unique <name> can be bound with the timed task. It returns and error if the <name> is already used.

func AddOnce Uses

func AddOnce(pattern string, job func(), name ...string) (*Entry, error)

AddOnce adds a timed task which can be run only once, to default cron object. A unique <name> can be bound with the timed task. It returns and error if the <name> is already used.

func AddSingleton Uses

func AddSingleton(pattern string, job func(), name ...string) (*Entry, error)

AddSingleton adds a singleton timed task, to default cron object. A singleton timed task is that can only be running one single instance at the same time. A unique <name> can be bound with the timed task. It returns and error if the <name> is already used.

func AddTimes Uses

func AddTimes(pattern string, times int, job func(), name ...string) (*Entry, error)

AddTimes adds a timed task which can be run specified times, to default cron object. A unique <name> can be bound with the timed task. It returns and error if the <name> is already used.

func Entries Uses

func Entries() []*Entry

Entries return all timed tasks as slice.

func Search(name string) *Entry

Search returns a scheduled task with the specified <name>. It returns nil if no found.

func (*Entry) Close Uses

func (entry *Entry) Close()

Close stops and removes the entry from cron.

func (*Entry) IsSingleton Uses

func (entry *Entry) IsSingleton() bool

IsSingleton return whether this entry is a singleton timed task.

func (*Entry) SetSingleton Uses

func (entry *Entry) SetSingleton(enabled bool)

SetSingleton sets the entry running in singleton mode.

func (*Entry) SetStatus Uses

func (entry *Entry) SetStatus(status int) int

SetStatus sets the status of the entry.

func (*Entry) SetTimes Uses

func (entry *Entry) SetTimes(times int)

SetTimes sets the times which the entry can run.

func (*Entry) Start Uses

func (entry *Entry) Start()

Start starts running the entry.

func (*Entry) Status Uses

func (entry *Entry) Status() int

Status returns the status of entry.

func (*Entry) Stop Uses

func (entry *Entry) Stop()

Stop stops running the entry.

Package gcron imports 15 packages (graph). Updated 2019-06-19. Refresh now. Tools for package owners.