mirror of https://github.com/shunfei/cronsun
job: better limiter
parent
6dc6680f99
commit
d98b8c5b37
8
job.go
8
job.go
|
@ -167,15 +167,13 @@ func (j *Job) limit() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// 更精确的控制是加锁
|
||||
// 两次运行时间极为接近的任务才可能出现控制不精确的情况
|
||||
count := atomic.LoadInt64(j.Count)
|
||||
if j.Parallels <= count {
|
||||
count := atomic.AddInt64(j.Count, 1)
|
||||
if j.Parallels < count {
|
||||
atomic.AddInt64(j.Count, -1)
|
||||
j.Fail(time.Now(), fmt.Sprintf("job[%s] running on[%s] running:[%d]", j.Key(), j.runOn, count))
|
||||
return true
|
||||
}
|
||||
|
||||
atomic.AddInt64(j.Count, 1)
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue