Skip to content

Commit dc22930

Browse files
author
Feng Zhou
committed
task bug fix.
1 parent 03eb77c commit dc22930

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

task/task.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -209,25 +209,27 @@ func (scheduler *Scheduler) runningJobCount() int {
209209
func (scheduler *Scheduler) runJobs(t time.Time) {
210210
runnableJobs := scheduler.getRunnableJobs(t)
211211
for _, job := range runnableJobs {
212-
function := func() {
213-
channel := make(chan bool, 1)
214-
go func() {
215-
job.run(t)
216-
channel <- true
217-
}()
218-
select {
219-
case <-channel:
220-
return
221-
case <-time.After(jobMaxExecutionDuration):
222-
jobStat := JobStat{
223-
IsSuccess: false,
224-
Err: ErrJobTimeout,
225-
ScheduledTime: t,
226-
RunDuration: jobMaxExecutionDuration,
212+
function := func(job Job) func() {
213+
return func() {
214+
channel := make(chan bool, 1)
215+
go func() {
216+
job.run(t)
217+
channel <- true
218+
}()
219+
select {
220+
case <-channel:
221+
return
222+
case <-time.After(jobMaxExecutionDuration):
223+
jobStat := JobStat{
224+
IsSuccess: false,
225+
Err: ErrJobTimeout,
226+
ScheduledTime: t,
227+
RunDuration: jobMaxExecutionDuration,
228+
}
229+
job.addStat(jobStat)
227230
}
228-
job.addStat(jobStat)
229231
}
230-
}
232+
}(job)
231233
if err := scheduler.workerPool.Submit(function); err != nil {
232234
jobStat := JobStat{IsSuccess: false, Err: err, ScheduledTime: t}
233235
job.addStat(jobStat)

0 commit comments

Comments
 (0)