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

Support passing of arbitrary name=value pairs to the --set argument to whenever #6

Open
wants to merge 2 commits 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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ in `deploy.rb`
These are the settings you can set:

set :whenever_name # default: "#{domain}_#{rails_env}"

You can also pass arbitrary key / value pairs to Whenever for use in the `schedule.rb` file via `whenever_sets`.

set :whenever_sets, our_host: ENV['HOST']

In this way you can access the value via the `@our_host` variable in `schedule.rb`.

## Contributing

Expand Down
20 changes: 17 additions & 3 deletions lib/mina/whenever/tasks.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
set :whenever_name, -> { "#{fetch(:domain)}_#{fetch(:rails_env)}" }

namespace :whenever do

# ### whenever_sets
# Pass optional name=value pairs to the --set argument of whenever.
# Specify these in your deploy.rb as key/value pairs, for example:
# set :whenever_sets, host: ENV['HOST']

sets = lambda { fetch(:whenever_sets) || {} }

set_string = lambda do
["environment=#{fetch(:rails_env)}",
"path=#{fetch(:current_path)}",
sets.call.map { |k, v| "#{k}=#{v}" }].flatten.join('&')
end

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 '#{set_string.call}'"
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 '#{set_string.call}'"
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 '#{set_string.call}'"
end
end
end