-
-
Save atombender/6bcff2c2d8fec32bc80ce1f57a8e61f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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