Skip to content

Commit

Permalink
add environment_variable support
Browse files Browse the repository at this point in the history
Fix mina-deploy#13

Signed-off-by: Laurent Vallar <[email protected]>
  • Loading branch information
Val committed Jun 28, 2018
1 parent aedfccc commit 78af0a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions lib/mina/whenever/tasks.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
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

desc 'Update crontab'
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

desc 'Write crontab'
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

0 comments on commit 78af0a4

Please sign in to comment.