mirror of
https://github.com/terorie/od-database-crawler.git
synced 2025-04-18 01:46: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 {
|
||||
logrus.WithError(err).
|
||||
Error("Failed to get new task")
|
||||
sleep(viper.GetDuration(ConfCooldown), appCtx)
|
||||
if !sleep(viper.GetDuration(ConfCooldown), appCtx) {
|
||||
goto shutdown
|
||||
}
|
||||
continue
|
||||
}
|
||||
if t == nil {
|
||||
@ -190,11 +192,11 @@ func hardShutdown(c context.Context) {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func sleep(d time.Duration, c context.Context) {
|
||||
func sleep(d time.Duration, c context.Context) bool {
|
||||
select {
|
||||
case <-time.After(d):
|
||||
break
|
||||
return true
|
||||
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
|
||||
for atomic.LoadInt32(&numActiveTasks) > config.Tasks {
|
||||
select {
|
||||
case <-c.Done():
|
||||
return false
|
||||
case <-time.After(time.Second):
|
||||
return true
|
||||
if !sleep(time.Second, c) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user