I have Thinking Sphinx setup and working however I am having a problem getting the Delayed Job rake tasks to start during deployment.
I have the following task in deploy.rb which appears to execute, however the delayed jobs are not processed – they stack up until I run rake ts:dd from the server command line:
namespace :thinkingsphinx do
desc 'Start Delayed Job Sphinx delta indexing'
task :dd do
run "cd #{current_path} && rake ts:dd RAILS_ENV=#{rails_env} &"
end
end
How can I get the delayed jobs to start running from the deployment script?
Thanks
Simon
The link Florian provided has code by Amit Solanki that works!
Here is what I did to get this to work with Capistrano:
Install gems
Create a file called
script/delayed_deltawith the contents:Configure Capistrano
Capistrano needs to start Sphinx and job_runner (with our
script/delayed_delta).Add something like this to the
deploy.rb:Configure
whenevergemIn your
config/schedule.rbadd lines to update Sphinx’s index and start job_runner if it isn’t already runningThis gets converted to a crontab that is run every 30 minutes to update sphinx
Final Notes and Lessons Learned
The
script/delayed_deltauses the daemon_generator gem to start the job_runner background worker script. This is equivalent to runningrake thinking_sphinx:delayed_deltason the console, but persistent.Make sure only one job_runner or
rake thinking_sphinx:delayed_deltasprocess is running at one timeLet Capistrano start both Sphinx (rake ts:rebuild) and
script/delayed_delta. I had problem when I started sphinx and delayed_deltas from different users or different environments