diff --git a/README.md b/README.md index ed210700..e866af4c 100644 --- a/README.md +++ b/README.md @@ -180,11 +180,23 @@ every 3.hours do end ``` -### Capistrano integration +### Capistrano Integration + +In your `Capfile` file: + +```ruby +require "whenever/capistrano" +``` + +Take a look at the [load:defaults task](https://github.com/javan/whenever/blob/master/lib/whenever/capistrano/v3/tasks/whenever.rake) (bottom of file) for options you can set. + +The Capistrano integration by default expects the `:application` variable to be set in order to scope jobs in the crontab. + +### Capistrano V2 integration Use the built-in Capistrano recipe for easy crontab updates with deploys. For Capistrano V3, see the next section. -In your "config/deploy.rb" file: +In your `config/deploy.rb` file: ```ruby require "whenever/capistrano" @@ -222,22 +234,6 @@ set :whenever_load_file, defer { "#{release_path}/somewhere/else/schedule.rb" } require "whenever/capistrano" ``` -### Capistrano V3 Integration - -In your "Capfile" file: - -```ruby -require "whenever/capistrano" -``` - -Take a look at the [load:defaults task](https://github.com/javan/whenever/blob/master/lib/whenever/capistrano/v3/tasks/whenever.rake) (bottom of file) for options you can set. For example, to namespace the crontab entries by application and stage do this in your "config/deploy.rb" file: - -```ruby -set :whenever_identifier, ->{ "#{fetch(:application)}_#{fetch(:stage)}" } -``` - -The Capistrano integration by default expects the `:application` variable to be set in order to scope jobs in the crontab. - ### Capistrano roles The first thing to know about the new roles support is that it is entirely diff --git a/lib/whenever/capistrano/v3/tasks/whenever.rake b/lib/whenever/capistrano/v3/tasks/whenever.rake index 9976e3ed..c7d3f0ec 100644 --- a/lib/whenever/capistrano/v3/tasks/whenever.rake +++ b/lib/whenever/capistrano/v3/tasks/whenever.rake @@ -45,8 +45,8 @@ namespace :load do set :whenever_roles, ->{ :db } set :whenever_command, ->{ [:bundle, :exec, :whenever] } set :whenever_command_environment_variables, ->{ fetch(:default_env).merge(rails_env: fetch(:whenever_environment)) } - set :whenever_identifier, ->{ fetch :application } - set :whenever_environment, ->{ fetch :rails_env, fetch(:stage, "production") } + set :whenever_identifier, ->{ "#{fetch(:application)}_#{fetch(:whenever_environment)}" } + set :whenever_environment, ->{ fetch(:rails_env, fetch(:stage, "production")) } set :whenever_variables, ->{ "environment=#{fetch :whenever_environment}" } set :whenever_load_file, ->{ nil } set :whenever_update_flags, ->{ "--update-crontab #{fetch :whenever_identifier} --set #{fetch :whenever_variables}" }