optimize events.Job function name

pull/388/head
Michael Li 10 months ago
parent 35c315a649
commit 7ba82d78bd
No known key found for this signature in database

@ -54,15 +54,15 @@ func RemoveJob(id EntryID) {
_defaultJobManager.Remove(id) _defaultJobManager.Remove(id)
} }
// ScheduleJob adds a Job to the Cron to be run on the given schedule. // Schedule adds a Job to the Cron to be run on the given schedule.
// The job is wrapped with the configured Chain. // The job is wrapped with the configured Chain.
func ScheduleJob(job Job) EntryID { func Schedule(job Job) EntryID {
return _defaultJobManager.Schedule(job) return _defaultJobManager.Schedule(job)
} }
// Schedule adds a Job to the Cron to be run on the given schedule. // OnTask adds a Job to the Cron to be run on the given schedule.
// The job is wrapped with the configured Chain. // The job is wrapped with the configured Chain.
func Schedule(s cron.Schedule, fn JobFn) EntryID { func OnTask(s cron.Schedule, fn JobFn) EntryID {
job := &simpleJob{ job := &simpleJob{
Schedule: s, Schedule: s,
Job: fn, Job: fn,

@ -18,7 +18,7 @@ func onMaxOnlineJob() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
events.Schedule(schedule, func() { events.OnTask(schedule, func() {
onlineUserKeys, err := _wc.Keys(conf.PrefixOnlineUser + "*") onlineUserKeys, err := _wc.Keys(conf.PrefixOnlineUser + "*")
if maxOnline := len(onlineUserKeys); err == nil && maxOnline > 0 { if maxOnline := len(onlineUserKeys); err == nil && maxOnline > 0 {
if _, err = _wc.PutHistoryMaxOnline(maxOnline); err != nil { if _, err = _wc.PutHistoryMaxOnline(maxOnline); err != nil {
@ -30,7 +30,7 @@ func onMaxOnlineJob() {
}) })
} }
func scheduleInnerJobs() { func scheduleJobs() {
cfg.Not("DisableJobManager", func() { cfg.Not("DisableJobManager", func() {
lazyInitial() lazyInitial()
onMaxOnlineJob() onMaxOnlineJob()

@ -46,8 +46,8 @@ func RouteWeb(e *gin.Engine) {
api.RegisterAlipayPubServant(e, newAlipayPubSrv(ds)) api.RegisterAlipayPubServant(e, newAlipayPubSrv(ds))
api.RegisterAlipayPrivServant(e, newAlipayPrivSrv(ds, client)) api.RegisterAlipayPrivServant(e, newAlipayPrivSrv(ds, client))
}) })
// shedule inner jobs if need // shedule jobs if need
scheduleInnerJobs() scheduleJobs()
} }
// lazyInitial do some package lazy initialize for performance // lazyInitial do some package lazy initialize for performance

Loading…
Cancel
Save