rails / solid_queue

Database-backed Active Job backend
MIT License
1.95k stars 130 forks source link

Revamp recurring tasks configuration and management #338

Closed rosa closed 2 months ago

rosa commented 2 months ago

This PR changes how recurring tasks are defined and how they're enqueued. They're no longer part of the dispatchers configuration or enqueued by the dispatchers. Instead, they have their own configuration file (config/recurring.yml, but it can be changed) and their own process, a new scheduler that's just in charge of enqueuing jobs for recurring tasks. Besides, the configuration for each task has been extended, and now it allows optionally specifying a queue and priority, and it also supports providing just a "command" (any Ruby code) instead of requiring a job class and arguments. The command will be eval'ed within a new SolidQueue::RecurringJob provided as well. This is how the new configuration looks like:

a_periodic_job:
  class: MyJob
  args: [ 42, { status: "custom_status" } ]
  schedule: every second
a_cleanup_task:
  command: "DeletedStuff.clear_all"
  queue: cleanup
  priority: 2
  schedule: every day at 9am