solid_queue icon indicating copy to clipboard operation
solid_queue copied to clipboard

Running rake commands directly via `command:` in recurring tasks configuration

Open marelons1337 opened this issue 6 months ago • 1 comments

Hi! I am moving my workers from http://github.com/javan/whenever schedule to solid_queue and the command key in recurring tasks could be improved with rake tasks handling. Here's a simple example based on my https://github.com/ankane/pghero setup

# config/schedule.rb
every 10.minutes do
  rake "pghero:capture_query_stats"
end

I believe this would be easy to implement by simply letting users do:

# config/schedule.yml
  capture_query_stats:
    command: "rake pghero:capture_query_stats"
    schedule: every 10.minutes

Currently it produces below error

undefined local variable or method 'capture_query_stats' for an instance of SolidQueue::RecurringJob

Is there something I am missing here and it's possible to execute the above? Right now we are using a simple workaround to get this to work:

# config/schedule.yml
  capture_query_stats:
    class: Rake::TaskJob
    args: "pghero:capture_query_stats"
    schedule: every 10 minutes
    queue: default
# app/jobs/rake/task_job.rb
class Rake::TaskJob < ApplicationJob
  queue_as :default
  self.queue_adapter = :solid_queue
  retry_on StandardError, attempts: 0

  def perform(command)
    require "rake"
    Rake.application.init
    Rake.application.load_rakefile
    Rake::Task[command].invoke
  end
end

But it does seem a bit ovet the top. I am happy to open a PR for this improvement.

marelons1337 avatar Jun 25 '25 13:06 marelons1337

Hey @marelons1337, sorry for the delay in replying! This is the same as https://github.com/rails/solid_queue/issues/379. You're not missing anything, as this is currently not supported. If you want to work on a PR to support it, go for it.

rosa avatar Jul 22 '25 12:07 rosa