Repository navigation
Expand file tree
/
Copy pathgcron.go
More file actions
131 lines (107 loc) · 4.15 KB
/
Copy pathgcron.go
File metadata and controls
131 lines (107 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright 2018 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
// Package gcron implements a cron pattern parser and job runner.
package gcron
import (
"math"
"time"
"github.com/gogf/gf/os/gtimer"
)
const (
STATUS_READY = gtimer.STATUS_READY
STATUS_RUNNING = gtimer.STATUS_RUNNING
STATUS_STOPPED = gtimer.STATUS_STOPPED
STATUS_CLOSED = gtimer.STATUS_CLOSED
gDEFAULT_TIMES = math.MaxInt32
)
var (
// Default cron object.
defaultCron = New()
)
// SetLogPath sets the logging folder path for default cron object.
func SetLogPath(path string) {
defaultCron.SetLogPath(path)
}
// GetLogPath returns the logging folder path of default cron object.
func GetLogPath() string {
return defaultCron.GetLogPath()
}
// SetLogLevel sets the logging level for default cron object.
func SetLogLevel(level int) {
defaultCron.SetLogLevel(level)
}
// GetLogLevel returns the logging level for default cron object.
func GetLogLevel() int {
return defaultCron.GetLogLevel()
}
// 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 Add(pattern string, job func(), name ...string) (*Entry, error) {
return defaultCron.Add(pattern, job, name...)
}
// 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 AddSingleton(pattern string, job func(), name ...string) (*Entry, error) {
return defaultCron.AddSingleton(pattern, job, name...)
}
// 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 AddOnce(pattern string, job func(), name ...string) (*Entry, error) {
return defaultCron.AddOnce(pattern, job, name...)
}
// 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 AddTimes(pattern string, times int, job func(), name ...string) (*Entry, error) {
return defaultCron.AddTimes(pattern, times, job, name...)
}
// DelayAdd adds a timed task to default cron object after <delay> time.
func DelayAdd(delay time.Duration, pattern string, job func(), name ...string) {
defaultCron.DelayAdd(delay, pattern, job, name...)
}
// DelayAddSingleton adds a singleton timed task after <delay> time to default cron object.
func DelayAddSingleton(delay time.Duration, pattern string, job func(), name ...string) {
defaultCron.DelayAddSingleton(delay, pattern, job, name...)
}
// DelayAddOnce adds a timed task after <delay> time to default cron object.
// This timed task can be run only once.
func DelayAddOnce(delay time.Duration, pattern string, job func(), name ...string) {
defaultCron.DelayAddOnce(delay, pattern, job, name...)
}
// DelayAddTimes adds a timed task after <delay> time to default cron object.
// This timed task can be run specified times.
func DelayAddTimes(delay time.Duration, pattern string, times int, job func(), name ...string) {
defaultCron.DelayAddTimes(delay, pattern, times, job, name...)
}
// Search returns a scheduled task with the specified <name>.
// It returns nil if no found.
func Search(name string) *Entry {
return defaultCron.Search(name)
}
// Remove deletes scheduled task which named <name>.
func Remove(name string) {
defaultCron.Remove(name)
}
// Size returns the size of the timed tasks of default cron.
func Size() int {
return defaultCron.Size()
}
// Entries return all timed tasks as slice.
func Entries() []*Entry {
return defaultCron.Entries()
}
// Start starts running the specified timed task named <name>.
func Start(name string) {
defaultCron.Start(name)
}
// Stop stops running the specified timed task named <name>.
func Stop(name string) {
defaultCron.Stop(name)
}