Skip to content

Add SolidQueue.recurring_task_job_class, accepting a class name - #814

Open
ngan wants to merge 1 commit into
rails:mainfrom
ngan:np-recurring-task-job-class
Open

ngan wants to merge 1 commit into
rails:mainfrom
ngan:np-recurring-task-job-class

Conversation

@ngan

@ngan ngan commented Oct 6, 2026 •

Copy link
Copy Markdown

Customizing the job class that runs command recurring tasks currently looks like this:

Rails.application.config.after_initialize do # or to_prepare
  SolidQueue::RecurringTask.default_job_class = MyRecurringCommandJob
end

This has two downsides:

  • It loads MyRecurringCommandJob at boot, along with SolidQueue::RecurringTask (and Active Record with it).
  • SolidQueue::RecurringTask lives in the engine's app/models, so it's reloadable. A value set in after_initialize is lost on the first reload; it has to be set in to_prepare to stick.

This adds a SolidQueue.recurring_task_job_class setting that takes the job class name:

# config/application.rb
config.solid_queue.recurring_task_job_class = "MyRecurringCommandJob"
  • It lives on the SolidQueue module, like the other settings, so it can be set through config.solid_queue and survives reloads.
  • The name is resolved when a task is first enqueued, so the job class isn't loaded at boot. A class is still accepted too.
  • It defaults to "SolidQueue::RecurringJob".

SolidQueue::RecurringTask.default_job_class (reader and writer) still works and delegates to the new setting, with a deprecation warning.

Setting `SolidQueue::RecurringTask.default_job_class` to an app job class
loads that class, and the `RecurringTask` model with it, at boot. And since
`RecurringTask` is reloadable, the setting is lost on reload unless it's set
in `to_prepare`.

The new `SolidQueue.recurring_task_job_class` setting lives on the
non-reloadable `SolidQueue` module, so it can be set as
`config.solid_queue.recurring_task_job_class` like the other settings. It
accepts a class name, resolved when a task is first enqueued, so the job
class stays autoloaded and can be customized with Zeitwerk's `on_load`.

`RecurringTask.default_job_class` is kept as a deprecated alias.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant