I am using a Mac OS running Snow Leopard 10.6.8, Ruby on Rails 3.2.2 and the DelayedJob gem. I would like to run some “command lines”/”tasks” from an inizializer so to start delayed workers.
In order to do that in my config/initializers/delayed_job.rb file I am trying to state the following:
if Rails.env.development?
system 'rake jobs:work'
elsif Rails.env.production?
system 'RAILS_ENV=production script/delayed_job stop'
system 'RAILS_ENV=production script/delayed_job -n 2 start'
end
However, the above code will start a lot of ruby processes and those rapidly slow my machine so I have to restart that. The remote machine run Linux Ubuntu 10.4.
How can I properly state that code so to run delayed workers?
In any case I think that, since on the local and remote machine are running two different Operating System, “command lines”/”tasks” should be different, as well…
Rather than using an initializer this should be done during deployment as your initializer is run for every instance of your app that is spawned.
Since you use capistrano I typically handle this like so:
in
config/deploy.rb:Since your wanting to spawn 2 workers this could be done by setting the delayed_job_args: