Skip to content

Instantly share code, notes, and snippets.

@contentfree contentfree/jobs.rake
Last active Dec 16, 2015

Embed
What would you like to do?
Daemonizing DelayedJob from a rake task. Useful for using DelayedJob outside of Rails (Hizzah Padrino!) Note: Requires rake >= 10.1 for TaskArguments#extras
namespace :jobs do
desc <<-EOD
Start delayed_job worker daemon. Requires passing start|stop|restart|reload|run|zap|status
to rake via `rake jobs:daemon[start]`. To pass arguments to Delayed::Command, call rake
like `rake jobs:daemon["--queue=something start"]` (Note the quotes wrapping the arguments!).
Available flags are: queues queue min_priority max_priority number_of_workers pid-dir
identifier monitor sleep-delay read-ahead prefix exit-on-complete
EOD
task :daemon, [:argv] => :environment do |t, args|
# If we have anything in args.extras we need to combined it with args[:argv]
# This lets us handle comma-separated values for --queues.
fake_argv = [args[:argv], args.extras].flatten.compact.join(',')
require 'delayed/command'
Delayed::Command.new(Shellwords.shellwords fake_argv).daemonize
end
end
@contentfree

This comment has been minimized.

Copy link
Owner Author

commented Apr 25, 2013

You have to do a few other things to get it to work with Padrino. Namely, you have to fake Rails.root: Put module Rails; def self.root; Padrino.root; end; end in Padrino's boot.rb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.