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 book lover

Growing Rails Applications in Practice

Check out our e-book. Learn to structure large Ruby on Rails codebases with the tools you already know and love.

  • Introduce design conventions for controllers and user-facing models
  • Create a system for growth
  • Build applications to last
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)