Better error in panic when accessing periodic jobs bundle in client that won't work#938
Merged
Merged
Conversation
6b66ce2 to
ce424e1
Compare
bgentry
approved these changes
May 30, 2025
Comment on lines
2087
to
+2095
| // PeriodicJobs returns the currently configured set of periodic jobs for the | ||
| // client, and can be used to add new ones or remove existing ones. | ||
| func (c *Client[TTx]) PeriodicJobs() *PeriodicJobBundle { return c.periodicJobs } | ||
| func (c *Client[TTx]) PeriodicJobs() *PeriodicJobBundle { |
Contributor
There was a problem hiding this comment.
Maybe we want to add a note to the doc string about this behavior too?
Contributor
Author
There was a problem hiding this comment.
Yep good point. Just added a new paragraph:
// This function should only be invoked on clients capable of running perioidc
// jobs. Running periodic jobs requires that the client be electable as leader
// to run maintenance services, and being electable as leader requires that a
// client be started. To be startable, a client must have Queues and Workers
// configured. Invoking this function will panic if these conditions aren't met.
…hat won't work Related to #937. If an insert-only client is created and the `PeriodicJobs()` bundle is accessed, it'll panic on a nil pointer error. The error is appropriate because if the client will never work jobs, it can never be started, which means it can never win leader election, which means that adding periodic jobs to it will never have any effect, but the bad error message is definitely not ideal. Here, detect this condition and panic with an error that better explains the situation to the caller. Fixes #937.
ce424e1 to
94d5e0b
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #937. If an insert-only client is created and the
PeriodicJobs()bundle is accessed, it'll panic on a nil pointer error.The error is appropriate because if the client will never work jobs, it
can never be started, which means it can never win leader election,
which means that adding periodic jobs to it will never have any effect,
but the bad error message is definitely not ideal.
Here, detect this condition and panic with an error that better explains
the situation to the caller.
Fixes #937.