Skip to content

Commit

Permalink
1.schedule代码调整,2.获取logger组件加入modules参数支持
Browse files Browse the repository at this point in the history
  • Loading branch information
keepchen committed Dec 28, 2023
1 parent 88fc347 commit 8c92ad6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
4 changes: 2 additions & 2 deletions sail/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func GetNats() *natsLib.Conn {
}

// GetLogger 获取日志实例
func GetLogger() *zap.Logger {
return logger.GetLogger()
func GetLogger(modules ...string) *zap.Logger {
return logger.GetLogger(modules...)
}

// Response http响应组件
Expand Down
38 changes: 18 additions & 20 deletions schedule/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ type TaskJob struct {
task func()
interval time.Duration
lockerKey string
cancelTaskChan chan struct{}
withoutOverlapping bool
cancelFunc func()
cancelTaskChan chan struct{}
}

var (
cancelFunc func()
cronJob *cron.Cron
)
var cronJob *cron.Cron

// Job 实例化任务
//
Expand All @@ -39,7 +37,7 @@ func Job(name string, task func()) *TaskJob {
cancelTaskChan: make(chan struct{}),
}

cancelFunc = func() {
job.cancelFunc = func() {
go func() {
job.cancelTaskChan <- struct{}{}
close(job.cancelTaskChan)
Expand Down Expand Up @@ -75,7 +73,7 @@ func (j *TaskJob) Every(interval time.Duration) (cancel func()) {
j.interval = interval
j.run()

cancel = cancelFunc
cancel = j.cancelFunc

return cancel
}
Expand All @@ -85,7 +83,7 @@ func (j *TaskJob) EverySecond() (cancel func()) {
j.interval = time.Second
j.run()

cancel = cancelFunc
cancel = j.cancelFunc

return cancel
}
Expand All @@ -95,7 +93,7 @@ func (j *TaskJob) EveryFiveSeconds() (cancel func()) {
j.interval = time.Second * 5
j.run()

cancel = cancelFunc
cancel = j.cancelFunc

return cancel
}
Expand All @@ -105,7 +103,7 @@ func (j *TaskJob) EveryTenSeconds() (cancel func()) {
j.interval = time.Second * 10
j.run()

cancel = cancelFunc
cancel = j.cancelFunc

return cancel
}
Expand All @@ -115,7 +113,7 @@ func (j *TaskJob) EveryThirtySeconds() (cancel func()) {
j.interval = time.Second * 30
j.run()

cancel = cancelFunc
cancel = j.cancelFunc

return cancel
}
Expand All @@ -125,7 +123,7 @@ func (j *TaskJob) EveryMinute() (cancel func()) {
j.interval = time.Minute
j.run()

cancel = cancelFunc
cancel = j.cancelFunc

return cancel
}
Expand All @@ -135,7 +133,7 @@ func (j *TaskJob) EveryFiveMinutes() (cancel func()) {
j.interval = time.Minute * 5
j.run()

cancel = cancelFunc
cancel = j.cancelFunc

return cancel
}
Expand All @@ -145,7 +143,7 @@ func (j *TaskJob) EveryTenMinutes() (cancel func()) {
j.interval = time.Minute * 10
j.run()

cancel = cancelFunc
cancel = j.cancelFunc

return cancel
}
Expand All @@ -155,7 +153,7 @@ func (j *TaskJob) EveryThirtyMinutes() (cancel func()) {
j.interval = time.Minute * 30
j.run()

cancel = cancelFunc
cancel = j.cancelFunc

return cancel
}
Expand All @@ -165,7 +163,7 @@ func (j *TaskJob) Hourly() (cancel func()) {
j.interval = time.Hour
j.run()

cancel = cancelFunc
cancel = j.cancelFunc

return cancel
}
Expand All @@ -175,7 +173,7 @@ func (j *TaskJob) Daily() (cancel func()) {
j.interval = time.Hour * 24
j.run()

cancel = cancelFunc
cancel = j.cancelFunc

return cancel
}
Expand All @@ -185,7 +183,7 @@ func (j *TaskJob) Weekly() (cancel func()) {
j.interval = time.Hour * 24 * 7
j.run()

cancel = cancelFunc
cancel = j.cancelFunc

return cancel
}
Expand All @@ -195,7 +193,7 @@ func (j *TaskJob) Monthly() (cancel func()) {
j.interval = time.Hour * 24 * 30
j.run()

cancel = cancelFunc
cancel = j.cancelFunc

return cancel
}
Expand All @@ -205,7 +203,7 @@ func (j *TaskJob) Yearly() (cancel func()) {
j.interval = time.Hour * 24 * 365
j.run()

cancel = cancelFunc
cancel = j.cancelFunc

return cancel
}
Expand Down

0 comments on commit 8c92ad6

Please sign in to comment.