Skip to content

Instantly share code, notes, and snippets.

@adampresley
Created June 14, 2023 20:51
Show Gist options
  • Select an option

  • Save adampresley/70b7f7e55d00d507eb6015885baa3074 to your computer and use it in GitHub Desktop.

Select an option

Save adampresley/70b7f7e55d00d507eb6015885baa3074 to your computer and use it in GitHub Desktop.
Work Ticker - workticker-part4.go
go func() {
ticker := time.NewTicker(wp.tickFrequency)
for {
select {
case <-ticker.C:
workItem, err := wp.workConfiguration.Retriever(wp.workConfiguration.Handler)
if err != nil && errors.Is(err, ErrNoWorkToRetrieve) {
continue
}
if err != nil {
wp.logger.WithError(err).Errorf("[%s] error retrieving work", wp.name)
continue
}
wp.workChan <- workItem
case <-ctx.Done():
wp.logger.Infof("[%s] closing worker pool ticker...", wp.name)
break
}
}
}()
wg.Wait()
close(wp.workChan)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment