diff --git a/os/gcron/gcron.go b/os/gcron/gcron.go index ae8ee328c..aeb63bc8b 100644 --- a/os/gcron/gcron.go +++ b/os/gcron/gcron.go @@ -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() } diff --git a/os/gtimer/gtimer.go b/os/gtimer/gtimer.go index 5cc849f7b..3491f6567 100644 --- a/os/gtimer/gtimer.go +++ b/os/gtimer/gtimer.go @@ -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. ) diff --git a/os/gtimer/gtimer_timer.go b/os/gtimer/gtimer_timer.go index 7022d87a3..2c43ba8fd 100644 --- a/os/gtimer/gtimer_timer.go +++ b/os/gtimer/gtimer_timer.go @@ -28,7 +28,7 @@ func New(options ...TimerOptions) *Timer { // Add adds a timing job to the timer, which runs in interval of . 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.