Documentation ¶
Overview ¶
Package gcron implements a cron pattern parser and job runner.
Example (CronAddSingleton) ¶
package main import ( "context" "time" "github.com/gogf/gf/v2/os/gcron" "github.com/gogf/gf/v2/os/glog" ) func main() { gcron.AddSingleton("* * * * * *", func() { glog.Println(context.TODO(), "doing") time.Sleep(2 * time.Second) }) select {} }
Output:
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 GetLogger() *glog.Logger
- func Remove(name string)
- func SetLogger(logger *glog.Logger)
- 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) AddEntry(pattern string, job func(), times int, singleton bool, 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) DelayAddEntry(delay time.Duration, pattern string, job func(), times int, singleton bool, ...)
- 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) GetLogger() *glog.Logger
- func (c *Cron) Remove(name string)
- func (c *Cron) Search(name string) *Entry
- func (c *Cron) SetLogger(logger *glog.Logger)
- 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 ( StatusReady = gtimer.StatusReady StatusRunning = gtimer.StatusRunning StatusStopped = gtimer.StatusStopped StatusClosed = gtimer.StatusClosed )
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.
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) AddEntry ¶
func (c *Cron) AddEntry(pattern string, job func(), times int, singleton bool, name ...string) (*Entry, error)
AddEntry creates and returns a new Entry object.
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.
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) DelayAddEntry ¶
func (c *Cron) DelayAddEntry(delay time.Duration, pattern string, job func(), times int, singleton bool, name ...string)
DelayAddEntry adds a timed task after `delay` time.
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) Search ¶
Search returns a scheduled task with the specified `name`. It returns nil if not found.
type Entry ¶
type Entry struct { Name string // Entry name. Job func() `json:"-"` // Callback function. Time time.Time // Registered time. // contains filtered or unexported fields }
Entry is timing 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.