Initialize the Delayed Jobs gem by starting the workers on application start
Try using this code:
system "RAILS_ENV=production #{Rails.root.join('script','delayed_job')} stop"
system "RAILS_ENV=production #{Rails.root.join('script','delayed_job')} -n 2 start"
Testing it in the console produced this output which indicates it should work:
Loading development environment (Rails 3.0.9)
ruby-1.9.2-p290 :001 > Rails.root.join('script','delayed_job')
=> #<Pathname:/home/devin/testsoapp/script/delayed_job>
ruby-1.9.2-p290 :002 > "RAILS_ENV=production #{Rails.root.join('script','delayed_job')} -n 2 start"
=> "RAILS_ENV=production /home/devin/testsoapp/script/delayed_job -n 2 start"
ruby-1.9.2-p290 :003 >
Setting up the Delay Jobs gem
To start your workers on application start I would just call the proper command from an initalizer. The code to do this would look like:
system "RAILS_ENV=production #{Rails.root.join('script','delayed_job')} stop"
system "RAILS_ENV=production #{Rails.root.join('script','delayed_job')} -n 2 start"
The path might be a little off and there most likely is a cleaner way to do it but I dont know of anything off of the top of my head.
Starting delayed_job at startup
You should create one recipe with the restart command.
namespace :delayed_job do
desc "Restart the delayed_job process"
task :restart, :roles => :app do
run "cd #{current_path}; RAILS_ENV=#{rails_env} script/delayed_job restart"
end
end
Then you add it to be executed at the end of your deployment.
after "deploy:update_code", "delayed_job:restart"
Related Topics
How to Stop Chromedriver from Opening Settings Tab Automatically
Ruby- Delete a Value from Sorted (Unique) Array at O(Log N) Runtime
Can Someone Explain the Following Code to Me
How to Convert an Octal Number to Decimal in Ruby
Rails 404 Error for Stylesheet or JavaScript Files
Elegant Way to Only Show Records If They Exist in Rails Erb
Hiding an Attribute in an Activerecord Model
Can Nokogiri Use Single Quotes for Attributes on Saving Xml
How to Display a Regexp Output in an Alphabetical List
Rails 3 - How to Handle Pg Error Incomplete Multibyte Character
Stubbing Controller Actions in Rspec Request Specs
Ruby: Module, Mixins and Blocks Confusing
Increase Timeout for Net::Http
Ruby on Windows7 - Could Not Find Gem
Undefined Method Error When Creating Delayed_Job Workers with Script/Delay_Job
Config Undefined in Environment Specific Configuration Files