Skip to content

Instantly share code, notes, and snippets.

@atombender
Created September 3, 2020 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atombender/6bcff2c2d8fec32bc80ce1f57a8e61f6 to your computer and use it in GitHub Desktop.
Save atombender/6bcff2c2d8fec32bc80ce1f57a8e61f6 to your computer and use it in GitHub Desktop.
// Run workers that process the queue.
func (c *Controller) startQueueWorkers() {
ctx, cancel := context.WithCancel(context.Background())
go func() {
// Wait for stop and then cancel
<-c.stopChan
cancel()
}()
for i := 1; i <= maxQueueWorkers; i++ {
go func() {
for {
task, err := c.taskQueue.Poll(ctx)
if err != nil {
if !errors.Is(err, context.Canceled) {
logger.Err(err).Msg("Failed polling queue")
}
continue
}
err = c.handleTask(ctx, task)
if err != nil {
c.scheduleRetry(task)
continue
}
}
}()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment