From 78af0a48bc16546dc54fb5bc6d77a39294699cda Mon Sep 17 00:00:00 2001 From: Laurent Vallar Date: Thu, 28 Jun 2018 08:41:21 +0200 Subject: [PATCH] add environment_variable support Fix #13 Signed-off-by: Laurent Vallar --- README.md | 4 ++++ lib/mina/whenever/tasks.rb | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0592960..2d01585 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,10 @@ These are the settings you can set: set :whenever_name # default: "#{domain}_#{rails_env}" + # See https://github.com/javan/whenever#define-your-own-job-types for environment variable configuration + set :whenever_environment_variable # default: fetch(:environment_variable) || 'RAILS_ENV' + set :whenever_environment # default: fetch(fetch(:whenever_environment_variable).downcase.to_sym) + ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/mina-deploy/mina-whenever. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. diff --git a/lib/mina/whenever/tasks.rb b/lib/mina/whenever/tasks.rb index 6e71089..d6419f2 100644 --- a/lib/mina/whenever/tasks.rb +++ b/lib/mina/whenever/tasks.rb @@ -1,11 +1,13 @@ -set :whenever_name, -> { "#{fetch(:domain)}_#{fetch(:rails_env)}" } +set :whenever_environment_variable, -> { fetch(:environment_variable) || 'RAILS_ENV' } +set :whenever_environment, -> { fetch(fetch(:environment_variable).downcase.to_sym) } +set :whenever_name, -> { "#{fetch(:domain)}_#{fetch(:whenever_environment)}" } namespace :whenever do desc 'Clear crontab' task clear: :environment do comment "Clear contrab for #{fetch(:whenever_name)}" in_path fetch(:current_path) do - command "#{fetch(:bundle_bin)} exec whenever --clear-crontab #{fetch(:whenever_name)} --set 'environment=#{fetch(:rails_env)}&path=#{fetch(:current_path)}'" + command "#{fetch(:bundle_bin)} exec whenever --clear-crontab #{fetch(:whenever_name)} --set 'environment_variable=#{fetch(:whenever_environment_variable)}&environment=#{fetch(:whenever_environment)}&path=#{fetch(:current_path)}'" end end @@ -13,7 +15,7 @@ task update: :environment do comment "Update crontab for #{fetch(:whenever_name)}" in_path fetch(:current_path) do - command "#{fetch(:bundle_bin)} exec whenever --update-crontab #{fetch(:whenever_name)} --set 'environment=#{fetch(:rails_env)}&path=#{fetch(:current_path)}'" + command "#{fetch(:bundle_bin)} exec whenever --update-crontab #{fetch(:whenever_name)} --set 'environment_variable=#{fetch(:whenever_environment_variable)}&environment=#{fetch(:whenever_environment)}&path=#{fetch(:current_path)}'" end end @@ -21,7 +23,7 @@ task write: :environment do comment "Write crontab for #{fetch(:whenever_name)}" in_path fetch(:current_path) do - command "#{fetch(:bundle_bin)} exec whenever --write-crontab #{fetch(:whenever_name)} --set 'environment=#{fetch(:rails_env)}&path=#{fetch(:current_path)}'" + command "#{fetch(:bundle_bin)} exec whenever --write-crontab #{fetch(:whenever_name)} --set 'environment_variable=#{fetch(:whenever_environment_variable)}&environment=#{fetch(:whenever_environment)}&path=#{fetch(:current_path)}'" end end end