Run clockwork only on one production instance (rails capistrano)

542 views Asked by At

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}
1

There are 1 answers

3
faron On BEST ANSWER

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