Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explanation for plan.init vs inside plan.work method. #8614

Merged
merged 2 commits into from Apr 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions worker/credentialvalidator/worker.go
Expand Up @@ -81,6 +81,15 @@ func NewWorker(config Config) (worker.Worker, error) {
err = catacomb.Invoke(catacomb.Plan{
Site: &v.catacomb,
Work: v.loop,
// The watcher needs to be added to the worker's catacomb plan
// here in order to be controlled by this worker's lifecycle events:
// for example, to be destroyed when this worker is destroyed, etc.
// We also add the watcher to the Plan.Init collection to ensure that
// the worker's Plan.Work method is executed after the watcher
// is initialised and watcher's changes collection obtains the changes.
// Watchers that are added using catacomb.Add method
// miss out on a first call of Worker's Plan.Work method and can, thus,
// be missing out on an initial change.
Init: []worker.Worker{w},
})
if err != nil {
Expand Down