Created
June 14, 2023 20:51
-
-
Save adampresley/70b7f7e55d00d507eb6015885baa3074 to your computer and use it in GitHub Desktop.
Work Ticker - workticker-part4.go
This file contains hidden or 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
| 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