Documentation ¶
Overview ¶
Package gcron implements a cron pattern parser and job runner.
Index ¶
- Constants
- func DelayAdd(delay time.Duration, pattern string, job func(), name ...string)
- func DelayAddOnce(delay time.Duration, pattern string, job func(), name ...string)
- func DelayAddSingleton(delay time.Duration, pattern string, job func(), name ...string)
- func DelayAddTimes(delay time.Duration, pattern string, times int, job func(), name ...string)
- func GetLogLevel() int
- func GetLogPath() string
- func Remove(name string)
- func SetLogLevel(level int)
- func SetLogPath(path string)
- func Size() int
- func Start(name string)
- func Stop(name string)
- type Cron
- func (c *Cron) Add(pattern string, job func(), name ...string) (*Entry, error)
- func (c *Cron) AddOnce(pattern string, job func(), name ...string) (*Entry, error)
- func (c *Cron) AddSingleton(pattern string, job func(), name ...string) (*Entry, error)
- func (c *Cron) AddTimes(pattern string, times int, job func(), name ...string) (*Entry, error)
- func (c *Cron) Close()
- func (c *Cron) DelayAdd(delay time.Duration, pattern string, job func(), name ...string)
- func (c *Cron) DelayAddOnce(delay time.Duration, pattern string, job func(), name ...string)
- func (c *Cron) DelayAddSingleton(delay time.Duration, pattern string, job func(), name ...string)
- func (c *Cron) DelayAddTimes(delay time.Duration, pattern string, times int, job func(), name ...string)
- func (c *Cron) Entries() []*Entry
- func (c *Cron) GetLogLevel() int
- func (c *Cron) GetLogPath() string
- func (c *Cron) Remove(name string)
- func (c *Cron) Search(name string) *Entry
- func (c *Cron) SetLogLevel(level int)
- func (c *Cron) SetLogPath(path string)
- func (c *Cron) Size() int
- func (c *Cron) Start(name ...string)
- func (c *Cron) Stop(name ...string)
- type Entry
- func Add(pattern string, job func(), name ...string) (*Entry, error)
- func AddOnce(pattern string, job func(), name ...string) (*Entry, error)
- func AddSingleton(pattern string, job func(), name ...string) (*Entry, error)
- func AddTimes(pattern string, times int, job func(), name ...string) (*Entry, error)
- func Entries() []*Entry
- func Search(name string) *Entry
Examples ¶
Constants ¶
const ( STATUS_READY = gtimer.STATUS_READY STATUS_RUNNING = gtimer.STATUS_RUNNING STATUS_STOPPED = gtimer.STATUS_STOPPED STATUS_CLOSED = gtimer.STATUS_CLOSED )
Variables ¶
This section is empty.
Functions ¶
func DelayAddOnce ¶
DelayAddOnce adds a timed task after <delay> time to default cron object. This timed task can be run only once.
func DelayAddSingleton ¶
DelayAddSingleton adds a singleton timed task after <delay> time to default cron object.
func DelayAddTimes ¶
DelayAddTimes adds a timed task after <delay> time to default cron object. This timed task can be run specified times.
func GetLogLevel ¶
func GetLogLevel() int
GetLogLevel returns the logging level for default cron object.
func GetLogPath ¶
func GetLogPath() string
GetLogPath returns the logging folder path of default cron object.
func SetLogLevel ¶
func SetLogLevel(level int)
SetLogLevel sets the logging level for default cron object.
func SetLogPath ¶
func SetLogPath(path string)
SetLogPath sets the logging folder path for default cron object.
Types ¶
type Cron ¶
type Cron struct {
// contains filtered or unexported fields
}
func (*Cron) Add ¶
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 ¶
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 ¶
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.
Example ¶
package main import ( "github.com/gogf/gf/g/os/gcron" "github.com/gogf/gf/g/os/glog" "time" ) func main() { gcron.AddSingleton("* * * * * *", func() { glog.Println("doing") time.Sleep(2 * time.Second) }) select {} }
Output:
func (*Cron) AddTimes ¶
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) DelayAddOnce ¶
DelayAddOnce adds a timed task after <delay> time. This timed task can be run only once.
func (*Cron) DelayAddSingleton ¶
DelayAddSingleton adds a singleton timed task after <delay> time.
func (*Cron) DelayAddTimes ¶
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) GetLogPath ¶
GetLogPath return the logging folder path.
func (*Cron) Search ¶
Search returns a scheduled task with the specified <name>. It returns nil if no found.
func (*Cron) SetLogLevel ¶
SetLogLevel sets the logging level.
func (*Cron) SetLogPath ¶
SetLogPath sets the logging folder path.
type Entry ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 Search ¶
Search returns a scheduled task with the specified <name>. It returns nil if no found.
func (*Entry) IsSingleton ¶
IsSingleton return whether this entry is a singleton timed task.
func (*Entry) SetSingleton ¶
SetSingleton sets the entry running in singleton mode.