File tree 1 file changed +15
-12
lines changed
1 file changed +15
-12
lines changed Original file line number Diff line number Diff line change @@ -170,7 +170,17 @@ func (s *TaskScheduler) checkProcessed(taskId string) bool {
170
170
}
171
171
s .lock .Lock ()
172
172
defer s .lock .Unlock ()
173
+
173
174
if _ , ok := s .processedTask [taskId ]; ! ok {
175
+ if s .count >= s .bufflen {
176
+ // 满了, 清除一个头部数据
177
+ delete (s .processedTask , s .taskProcessedTime [s .head ].taskId )
178
+ s .head ++
179
+ s .count --
180
+ if s .head >= s .bufflen {
181
+ s .head = 0
182
+ }
183
+ }
174
184
s .processedTask [taskId ] = true
175
185
s .taskProcessedTime [s .tail ] = processTime {
176
186
t : time .Now (),
@@ -180,24 +190,17 @@ func (s *TaskScheduler) checkProcessed(taskId string) bool {
180
190
if s .tail >= s .bufflen {
181
191
s .tail = 0
182
192
}
183
- if s .count >= s .bufflen {
184
- // 满了, head 被覆盖
185
- s .head ++
186
- if s .head >= s .bufflen {
187
- s .head = 0
188
- }
189
- } else {
190
- s .count ++
191
- }
193
+ s .count ++
192
194
return true
193
195
} else {
194
196
return false
195
197
}
196
198
}
197
199
198
200
func (s * TaskScheduler ) cleanProcessTask () {
199
- ticker := time .NewTicker (3 * time .Second )
201
+ ticker := time .NewTicker (time .Second )
200
202
for {
203
+
201
204
select {
202
205
case <- s .ctx .Done ():
203
206
return
@@ -212,12 +215,12 @@ func (s *TaskScheduler) cleanProcessTask() {
212
215
}()
213
216
214
217
for s .count > 0 {
215
- if s .taskProcessedTime [s .head ].t .After (time .Now ().Add (- 5 * time .Second )) {
218
+ if s .taskProcessedTime [s .head ].t .Before (time .Now ().Add (- time .Second )) {
216
219
delete (s .processedTask , s .taskProcessedTime [s .head ].taskId )
217
220
s .head ++
218
221
s .count --
219
222
if s .head >= s .bufflen {
220
- s .bufflen = 0
223
+ s .head = 0
221
224
}
222
225
} else {
223
226
break
You can’t perform that action at this time.
0 commit comments