set environment and path earlier so schedule files do conditionals with them

This commit is contained in:
Javan Makhmali 2010-10-25 21:14:45 -04:00
parent b255926e05
commit 9f73bcb469
3 changed files with 24 additions and 1 deletions

View File

@ -9,7 +9,7 @@ module Whenever
@template = options.delete(:template)
@job_template = options.delete(:job_template) || ":job"
@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
end

View File

@ -1,9 +1,13 @@
set :environment, "production"
set :path, Whenever.path
# http://blog.scoutapp.com/articles/2010/09/07/rvm-and-cron-in-production
set :job_template, "/bin/bash -l -c ':job'"
job_type :command, ":task :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'))
job_type :runner, "cd :path && script/rails runner -e :environment ':task' :output"
else

View File

@ -51,6 +51,25 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
assert_no_match /bash/, @output
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