Invoke delayed_job capistrano tasks only on specific servers

后端 未结 1 1812
滥情空心
滥情空心 2021-02-06 04:24

I have a dedicated server for delayed_job tasks. I want to start, stop, and restart delayed_job workers on only this server. I am using the capistrano recipes p

相关标签:
1条回答
  • 2021-02-06 04:46

    When you define a task in Capistrano you can restrict the execution of the task to specific role(s). The way you do this is by passing the :role option.

    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 fetches the list of roles from the :delayed_job_server_role configuration variable.

    Back to your problem, to narrow the execution of the tasks to a specific group of servers, define a new role (for example worker) in your deploy.rb

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

    Then set the :delayed_job_server_role to that name

    set :delayed_job_server_role, :worker
    

    That's all. Now the tasks will be executed, but only to the servers listed in the :worker role.

    0 讨论(0)
提交回复
热议问题