mirror of
https://github.com/terorie/od-database-crawler.git
synced 2025-04-19 18:36:43 +00:00
Fix sleeps
This commit is contained in:
parent
25d0b0042c
commit
4ef4ab13a8
10
main.go
10
main.go
@ -97,7 +97,9 @@ func cmdBase(_ *cobra.Command, _ []string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).
|
logrus.WithError(err).
|
||||||
Error("Failed to get new task")
|
Error("Failed to get new task")
|
||||||
sleep(viper.GetDuration(ConfCooldown), appCtx)
|
if !sleep(viper.GetDuration(ConfCooldown), appCtx) {
|
||||||
|
goto shutdown
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if t == nil {
|
if t == nil {
|
||||||
@ -190,11 +192,11 @@ func hardShutdown(c context.Context) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sleep(d time.Duration, c context.Context) {
|
func sleep(d time.Duration, c context.Context) bool {
|
||||||
select {
|
select {
|
||||||
case <-time.After(d):
|
case <-time.After(d):
|
||||||
break
|
return true
|
||||||
case <-c.Done():
|
case <-c.Done():
|
||||||
break
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,11 +65,8 @@ func scheduleNewTask(c context.Context, remote *OD) bool {
|
|||||||
|
|
||||||
// Sleep if max number of tasks are active
|
// Sleep if max number of tasks are active
|
||||||
for atomic.LoadInt32(&numActiveTasks) > config.Tasks {
|
for atomic.LoadInt32(&numActiveTasks) > config.Tasks {
|
||||||
select {
|
if !sleep(time.Second, c) {
|
||||||
case <-c.Done():
|
break
|
||||||
return false
|
|
||||||
case <-time.After(time.Second):
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user