mirror of
https://gitee.com/johng/gf.git
synced 2024-11-30 03:07:45 +08:00
improve package gcron
This commit is contained in:
parent
e10240bd7c
commit
43180ef239
@ -8,7 +8,7 @@
|
||||
package gcron
|
||||
|
||||
import (
|
||||
"math"
|
||||
"github.com/gogf/gf/os/glog"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/os/gtimer"
|
||||
@ -19,7 +19,6 @@ const (
|
||||
StatusRunning = gtimer.StatusRunning
|
||||
StatusStopped = gtimer.StatusStopped
|
||||
StatusClosed = gtimer.StatusClosed
|
||||
defaultTimes = math.MaxInt32
|
||||
)
|
||||
|
||||
var (
|
||||
@ -27,22 +26,36 @@ var (
|
||||
defaultCron = New()
|
||||
)
|
||||
|
||||
// SetLogger sets the logger for cron.
|
||||
func SetLogger(logger *glog.Logger) {
|
||||
defaultCron.SetLogger(logger)
|
||||
}
|
||||
|
||||
// GetLogger returns the logger in the cron.
|
||||
func GetLogger() *glog.Logger {
|
||||
return defaultCron.GetLogger()
|
||||
}
|
||||
|
||||
// SetLogPath sets the logging folder path for default cron object.
|
||||
// Deprecated, use SetLogger instead.
|
||||
func SetLogPath(path string) {
|
||||
defaultCron.SetLogPath(path)
|
||||
}
|
||||
|
||||
// GetLogPath returns the logging folder path of default cron object.
|
||||
// Deprecated, use GetLogger instead.
|
||||
func GetLogPath() string {
|
||||
return defaultCron.GetLogPath()
|
||||
}
|
||||
|
||||
// SetLogLevel sets the logging level for default cron object.
|
||||
// Deprecated, use SetLogger instead.
|
||||
func SetLogLevel(level int) {
|
||||
defaultCron.SetLogLevel(level)
|
||||
}
|
||||
|
||||
// GetLogLevel returns the logging level for default cron object.
|
||||
// Deprecated, use GetLogger instead.
|
||||
func GetLogLevel() int {
|
||||
return defaultCron.GetLogLevel()
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ package gtimer
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/container/gtype"
|
||||
"math"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -47,7 +46,6 @@ const (
|
||||
StatusStopped = 2 // Job or Timer is stopped.
|
||||
StatusClosed = -1 // Job or Timer is closed and waiting to be deleted.
|
||||
panicExit = "exit" // panicExit is used for custom job exit with panic.
|
||||
defaultTimes = math.MaxInt32 // defaultTimes is the default limit running times, a big number.
|
||||
defaultTimerInterval = 100 // defaultTimerInterval is the default timer interval in milliseconds.
|
||||
commandEnvKeyForInterval = "gf.gtimer.interval" // commandEnvKeyForInterval is the key for command argument or environment configuring default interval duration for timer.
|
||||
)
|
||||
|
@ -28,7 +28,7 @@ func New(options ...TimerOptions) *Timer {
|
||||
|
||||
// Add adds a timing job to the timer, which runs in interval of <interval>.
|
||||
func (t *Timer) Add(interval time.Duration, job JobFunc) *Entry {
|
||||
return t.createEntry(interval, job, false, defaultTimes, StatusReady)
|
||||
return t.createEntry(interval, job, false, -1, StatusReady)
|
||||
}
|
||||
|
||||
// AddEntry adds a timing job to the timer with detailed parameters.
|
||||
@ -48,7 +48,7 @@ func (t *Timer) AddEntry(interval time.Duration, job JobFunc, singleton bool, ti
|
||||
|
||||
// AddSingleton is a convenience function for add singleton mode job.
|
||||
func (t *Timer) AddSingleton(interval time.Duration, job JobFunc) *Entry {
|
||||
return t.createEntry(interval, job, true, defaultTimes, StatusReady)
|
||||
return t.createEntry(interval, job, true, -1, StatusReady)
|
||||
}
|
||||
|
||||
// AddOnce is a convenience function for adding a job which only runs once and then exits.
|
||||
|
Loading…
Reference in New Issue
Block a user