Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add environment_variable support #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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