Read more

Whenever requires you to set the application attribute in the Capistrano config

Emanuel
December 16, 2020Software engineer at makandra GmbH

Whenever requires you to set the application attribute in your Capistrano configuration Show archive.org snapshot . Otherwise your cronjobs are created multiple times.

Illustration money motivation

Opscomplete powered by makandra brand

Save money by migrating from AWS to our fully managed hosting in Germany.

  • Trusted by over 100 customers
  • Ready to use with Ruby, Node.js, PHP
  • Proactive management by operations experts
Read more Show archive.org snapshot

Example entry in config/deploy.rb:

set :application, 'some-app' # allows "set :whenever_identifier, ->{ "#{fetch(:application)}_#{fetch(:stage)}" }" to work as expected

Good

Then the crontab -l output will look like this:

# Begin Whenever generated tasks for: some-app_staging

34 23 * * * /bin/bash -l -c 'cd /var/www/some-app_staging/releases/20201215171150 && RAILS_ENV=staging bundle exec rake some-task'

# End Whenever generated tasks for: some-app_staging

Bad

Instead of a non unique identifier with the default value, that can not be replaced by Whenever (the release folder changes every deploy):

# Begin Whenever generated tasks for: /var/www/some-app_staging/releases/20201215171150

34 23 * * * /bin/bash -l -c 'cd /var/www/some-app_staging/releases/20201215171150 && RAILS_ENV=staging bundle exec rake some-task'

# End Whenever generated tasks for: /var/www/some-app_staging/releases/20201215171150

# Begin Whenever generated tasks for: /var/www/some-app_staging/releases/20201215171000

34 23 * * * /bin/bash -l -c 'cd /var/www/some-app_staging/releases/20201215171000 && RAILS_ENV=staging bundle exec rake some-task'

# End Whenever generated tasks for: /var/www/some-app_staging/releases/20201215171000
Posted by Emanuel to makandra dev (2020-12-16 14:22)