set environment and path earlier so schedule files do conditionals with them
This commit is contained in:
parent
b255926e05
commit
9f73bcb469
@ -9,7 +9,7 @@ module Whenever
|
|||||||
@template = options.delete(:template)
|
@template = options.delete(:template)
|
||||||
@job_template = options.delete(:job_template) || ":job"
|
@job_template = options.delete(:job_template) || ":job"
|
||||||
@options[:output] = Whenever::Output::Redirection.new(options[:output]).to_s if options.has_key?(:output)
|
@options[:output] = Whenever::Output::Redirection.new(options[:output]).to_s if options.has_key?(:output)
|
||||||
#@options[:environment] ||= :production
|
@options[:environment] ||= :production
|
||||||
@options[:path] ||= Whenever.path
|
@options[:path] ||= Whenever.path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
|
set :environment, "production"
|
||||||
|
set :path, Whenever.path
|
||||||
|
|
||||||
# http://blog.scoutapp.com/articles/2010/09/07/rvm-and-cron-in-production
|
# http://blog.scoutapp.com/articles/2010/09/07/rvm-and-cron-in-production
|
||||||
set :job_template, "/bin/bash -l -c ':job'"
|
set :job_template, "/bin/bash -l -c ':job'"
|
||||||
|
|
||||||
job_type :command, ":task :output"
|
job_type :command, ":task :output"
|
||||||
job_type :rake, "cd :path && RAILS_ENV=:environment rake :task --silent :output"
|
job_type :rake, "cd :path && RAILS_ENV=:environment rake :task --silent :output"
|
||||||
|
|
||||||
|
# Create a runner job that's appropriate for the Rails version,
|
||||||
if File.exists?(File.join(Whenever.path, 'script', 'rails'))
|
if File.exists?(File.join(Whenever.path, 'script', 'rails'))
|
||||||
job_type :runner, "cd :path && script/rails runner -e :environment ':task' :output"
|
job_type :runner, "cd :path && script/rails runner -e :environment ':task' :output"
|
||||||
else
|
else
|
||||||
|
@ -52,6 +52,25 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "A plain command that is conditional on default environent and path" do
|
||||||
|
setup do
|
||||||
|
Whenever.expects(:path).at_least_once.returns('/what/you/want')
|
||||||
|
@output = Whenever.cron \
|
||||||
|
<<-file
|
||||||
|
set :job_template, nil
|
||||||
|
if environment == 'production' && path == '/what/you/want'
|
||||||
|
every 2.hours do
|
||||||
|
command "blahblah"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
file
|
||||||
|
end
|
||||||
|
|
||||||
|
should "output the command" do
|
||||||
|
assert_match /blahblah/, @output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# runner
|
# runner
|
||||||
|
|
||||||
context "A runner with path set" do
|
context "A runner with path set" do
|
||||||
|
Loading…
Reference in New Issue
Block a user