Capistrano tasks for BackgrounDRb

We’re using Ezra’s BackgrounDRb to handle batch processing of CSVs uploaded to our Rails application and have been very happy with the results. Our users now even get a progress indicator as we process their job.

When it came time to deploy the new functionality to our severs, however, we ran into a known issue where the BDRb process did not detach from Capistrano, and therefore got killed as Capistrano exits.

We solved this issue with the following BackgrounDRb Capistrano tasks:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
desc "Stop the backgroundrb server"
task :stop_backgroundrb , :roles => :app do
  run "cd #{current_path} && ./script/backgroundrb/stop"
end

desc "Start the backgroundrb server"
task :start_backgroundrb , :roles => :app do
  run "cd #{current_path} && RAILS_ENV=production nohup ./script/backgroundrb/start -d  > /dev/null 2>&1"
end

desc "Start the backgroundrb server"
task :restart_backgroundrb, :roles => :app do
  stop_backgroundrb
  start_backgroundrb
end

And then we enhanced the restart task so that it would restart BackgrounDRb in addition to our Mongrel processes:

1
2
3
4
5
task :restart, :roles => :app do
  stop_mongrel_cluster
  restart_backgroundrb
  start_mongrel_cluster
end

1 Response to “Capistrano tasks for BackgrounDRb”

  1. # Nate Murray Says:
    For the new version of BackgrounDRb you could use the following command:
    
      desc "Start the backgroundrb server" 
      task :start_backgroundrb , :roles => :app do
        run "cd #{current_path} && nohup ./script/backgroundrb start -- -r production > #{current_path}/log/backgroundrb-cap.log 2>&1" 
      end
    
    

    -Nate Murray