8000 Better error in panic when accessing periodic jobs bundle in client that won't work by brandur · Pull Request #938 · riverqueue/river · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Better error in panic when accessing periodic jobs bundle in client that won't work #938

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

Merged
merged 1 commit into from
May 30, 2025

Conversation

brandur
Copy link
Contributor
@brandur brandur commented May 29, 2025

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.

@brandur brandur force-pushed the brandur-better-periodic-job-error branch from 6b66ce2 to ce424e1 Compare May 29, 2025 05:26
@brandur brandur requested a review from bgentry May 29, 2025 05:30
client.go Outdated
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we want to add a note to the doc string about this behavior too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@brandur brandur force-pushed the brandur-better-periodic-job-error branch from ce424e1 to 94d5e0b Compare May 30, 2025 06:20
@brandur brandur merged commit fd01492 into master May 30, 2025
10 checks passed
@brandur brandur deleted the brandur-better-periodic-job-error branch May 30, 2025 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to insert a periodic job from external service
2 participants
0