feat: add timeout capabilities to worker pool

This commit is contained in:
Alexander Navarro 2024-11-29 17:38:57 -03:00
parent eeefceb2fc
commit f8c068a7f3
2 changed files with 36 additions and 7 deletions

View file

@ -19,7 +19,7 @@ func (platform *Platform) FetchCollections(fetcher Fetcher, start_pagination Pag
// fmt.Printf("Requesting offset: %v\n", offset)
if offset == 10 {
return nil, fmt.Errorf("Simulated error jeje")
time.Sleep(time.Second * 5)
}
pagination := start_pagination
@ -34,12 +34,14 @@ func (platform *Platform) FetchCollections(fetcher Fetcher, start_pagination Pag
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
config := &WorkConfig{
max_workers: 5,
max_retries: 2,
base_retry_time: time.Second,
rate_limit: NewRateLimit(5, time.Minute),
timeout: time.Second * 2,
}
tasks := make(chan int)
@ -69,7 +71,6 @@ loop:
}
fmt.Printf("There was an error: %v\n", error)
cancel()
case <-ctx.Done():
break loop
case <-done: