Only call delayed_job capistrano tasks on specific servers

I have a dedicated server for delayed_job tasks. I want to start, stop and restart protracted workers on the server only . I use capistrano recipes provided by delayed_job.

When I only had 1 server, this was my configuration:

before "deploy:restart", "delayed_job:stop" after "deploy:restart", "delayed_job:start" after "deploy:stop", "delayed_job:stop" after "deploy:start", "delayed_job:start" 

Now I want these bindings only apply to a separate server delayed_job ( role :delayed_job <ip address> ). Can this be done elegantly? Should I transfer each delayed_job task to a meta task? Or write my own tasks, and not use the ones that were provided by the delayed work?

+8
ruby capistrano delayed-job
source share
1 answer

When you define a task in Capistrano, you can restrict the task to a specific role. How do you do this by passing the :role parameter.

It seems the default delayed_job Capistrano recipe does this.

 desc "Stop the delayed_job process" task :stop, :roles => lambda { roles } do run "cd #{current_path};#{rails_env} script/delayed_job stop" end 

According to the source code, the task retrieves the list of roles from the configuration variable :delayed_job_server_role .

Let's get back to your problem in order to narrow down the execution of tasks to a specific group of servers, to define a new role (for example, a worker) in deploy.rb

 role :worker, "192.168.1.1" # Assign the IP of your machine 

Then set :delayed_job_server_role to this name

 set :delayed_job_server_role, :worker 

It's all. Now the tasks will be completed, but only for the servers listed in the role :worker .

+12
source share

All Articles