Last active
December 16, 2015 16:20
-
-
Save contentfree/5462799 to your computer and use it in GitHub Desktop.
Daemonizing DelayedJob from a rake task. Useful for using DelayedJob outside of Rails (Hizzah Padrino!) Note: Requires rake >= 10.1 for TaskArguments#extras
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.