Documentation ¶
Overview ¶
Package gcron implements a cron pattern parser and job runner.
Index ¶
- Constants
- func DelayAdd(ctx context.Context, delay time.Duration, pattern string, job JobFunc, ...)
- func DelayAddOnce(ctx context.Context, delay time.Duration, pattern string, job JobFunc, ...)
- func DelayAddSingleton(ctx context.Context, delay time.Duration, pattern string, job JobFunc, ...)
- func DelayAddTimes(ctx context.Context, delay time.Duration, pattern string, times int, ...)
- func GetLogger() glog.ILogger
- func Remove(name string)
- func SetLogger(logger glog.ILogger)
- func Size() int
- func Start(name ...string)
- func Stop(name ...string)
- type Cron
- func (c *Cron) Add(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)
- func (c *Cron) AddEntry(ctx context.Context, pattern string, job JobFunc, times int, isSingleton bool, ...) (*Entry, error)
- func (c *Cron) AddOnce(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)
- func (c *Cron) AddSingleton(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)
- func (c *Cron) AddTimes(ctx context.Context, pattern string, times int, job JobFunc, name ...string) (*Entry, error)
- func (c *Cron) Close()
- func (c *Cron) DelayAdd(ctx context.Context, delay time.Duration, pattern string, job JobFunc, ...)
- func (c *Cron) DelayAddEntry(ctx context.Context, delay time.Duration, pattern string, job JobFunc, ...)
- func (c *Cron) DelayAddOnce(ctx context.Context, delay time.Duration, pattern string, job JobFunc, ...)
- func (c *Cron) DelayAddSingleton(ctx context.Context, delay time.Duration, pattern string, job JobFunc, ...)
- func (c *Cron) DelayAddTimes(ctx context.Context, delay time.Duration, pattern string, times int, ...)
- func (c *Cron) Entries() []*Entry
- func (c *Cron) GetLogger() glog.ILogger
- func (c *Cron) Remove(name string)
- func (c *Cron) Search(name string) *Entry
- func (c *Cron) SetLogger(logger glog.ILogger)
- func (c *Cron) Size() int
- func (c *Cron) Start(name ...string)
- func (c *Cron) Stop(name ...string)
- type Entry
- func Add(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)
- func AddOnce(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)
- func AddSingleton(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)
- func AddTimes(ctx context.Context, pattern string, times int, job JobFunc, name ...string) (*Entry, error)
- func Entries() []*Entry
- func Search(name string) *Entry
- type JobFunc
Constants ¶
const ( StatusReady = gtimer.StatusReady StatusRunning = gtimer.StatusRunning StatusStopped = gtimer.StatusStopped StatusClosed = gtimer.StatusClosed )
Variables ¶
This section is empty.
Functions ¶
func DelayAdd ¶
func DelayAdd(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)
DelayAdd adds a timed task to default cron object after `delay` time.
func DelayAddOnce ¶
func DelayAddOnce(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)
DelayAddOnce adds a timed task after `delay` time to default cron object. This timed task can be run only once.
func DelayAddSingleton ¶
func DelayAddSingleton(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)
DelayAddSingleton adds a singleton timed task after `delay` time to default cron object.
func DelayAddTimes ¶
func DelayAddTimes(ctx context.Context, delay time.Duration, pattern string, times int, job JobFunc, name ...string)
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 ¶
func (c *Cron) Add(ctx context.Context, pattern string, job JobFunc, 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) AddEntry ¶
func (c *Cron) AddEntry(ctx context.Context, pattern string, job JobFunc, times int, isSingleton bool, name ...string) (*Entry, error)
AddEntry creates and returns a new Entry object.
func (*Cron) AddOnce ¶
func (c *Cron) AddOnce(ctx context.Context, pattern string, job JobFunc, 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 ¶
func (c *Cron) AddSingleton(ctx context.Context, pattern string, job JobFunc, 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.
func (*Cron) AddTimes ¶
func (c *Cron) AddTimes(ctx context.Context, pattern string, times int, job JobFunc, 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) DelayAdd ¶
func (c *Cron) DelayAdd(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)
DelayAdd adds a timed task after `delay` time.
func (*Cron) DelayAddEntry ¶
func (c *Cron) DelayAddEntry(ctx context.Context, delay time.Duration, pattern string, job JobFunc, times int, isSingleton bool, name ...string)
DelayAddEntry adds a timed task after `delay` time.
func (*Cron) DelayAddOnce ¶
func (c *Cron) DelayAddOnce(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)
DelayAddOnce adds a timed task after `delay` time. This timed task can be run only once.
func (*Cron) DelayAddSingleton ¶
func (c *Cron) DelayAddSingleton(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)
DelayAddSingleton adds a singleton timed task after `delay` time.
func (*Cron) DelayAddTimes ¶
func (c *Cron) DelayAddTimes(ctx context.Context, delay time.Duration, pattern string, times int, job JobFunc, name ...string)
DelayAddTimes adds a timed task after `delay` time. This timed task can be run specified times.
func (*Cron) Entries ¶
Entries return all timed tasks as slice(order by registered time asc).
func (*Cron) GetLogger ¶
GetLogger returns the logger in the cron.
func (*Cron) Remove ¶
Remove deletes scheduled task which named `name`.
func (*Cron) Search ¶
Search returns a scheduled task with the specified `name`. It returns nil if not found.
func (*Cron) SetLogger ¶
SetLogger sets the logger for cron.
func (*Cron) Start ¶
Start starts running the specified timed task named `name`. If no`name` specified, it starts the entire cron.
type Entry ¶
type Entry struct { Name string // Entry name. Job JobFunc `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 ¶
func AddTimes(ctx context.Context, pattern string, times int, job JobFunc, 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 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.
func (*Entry) SetStatus ¶
SetStatus sets the status of the entry.
func (*Entry) SetTimes ¶
SetTimes sets the times which the entry can run.