简体   繁体   中英

Run clockwork only on one production instance (rails capistrano)

I have a production server with two instances app1 and app2 to which I use capistrano to deploy my application, ie: cap app1 deploy, cap app2 deploy.

I am now configuring the clockwork to schedule my delayed jobs. But what happens the jobs are scheduled twice, because the clockwork process runs on both app1 and app2 after application is deployed.

How can I force the capistrano to run the clockwork process only on app2 ?

Thanks for a hint. Miroslav

SOLUTION

Add the following settings into the deploy.rb:

set :clockwork_role, :clock

And then configure only one of the instances to use the role :clock, ie:

server 'URL', user: 'deploy', roles: %w{app db web clock}

In your case you can set some config variable to true in one case, and to false in the second, and check it when setting clockwork.

But want to mention that you are using different 'stages' (which are usually 'staging', 'production', 'qa', 'features', etc) for the different servers of one stage. Capistrano has 'roles' (app, db, background jobs, etc) each can have several servers.

Also please mention which capistrano version you're using - there were big changes from 2 to 3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM