From 6bf363b7237cd8f4a007531f391209f7e2b0234a Mon Sep 17 00:00:00 2001 From: Javan Makhmali Date: Fri, 4 Sep 2009 16:48:33 -0400 Subject: [PATCH] don't try to combine @shortcut jobs --- lib/job_list.rb | 17 ++++++++++++----- test/output_at_test.rb | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/lib/job_list.rb b/lib/job_list.rb index dd437fb..2130b33 100644 --- a/lib/job_list.rb +++ b/lib/job_list.rb @@ -112,7 +112,7 @@ module Whenever # them into one that runs on the 2nd minute at the 3rd and 4th hour. # def combine(entries) - entries.map! { |entry| entry.split(/ +/,6 )} + entries.map! { |entry| entry.split(/ +/, 6) } 0.upto(4) do |f| (entries.length-1).downto(1) do |i| next if entries[i][f] == '*' @@ -134,18 +134,25 @@ module Whenever def cron_jobs return if @jobs.empty? - output = [] + shortcut_jobs = [] + regular_jobs = [] + @jobs.each do |time, jobs| jobs.each do |job| Whenever::Output::Cron.output(time, job) do |cron| cron << " >> #{job.cron_log} 2>&1" if job.cron_log cron << "\n\n" - output << cron + + if cron.starts_with?("@") + shortcut_jobs << cron + else + regular_jobs << cron + end end end end - - combine(output).join + + shortcut_jobs.join + combine(regular_jobs).join end end diff --git a/test/output_at_test.rb b/test/output_at_test.rb index 2f160ce..bc99d43 100644 --- a/test/output_at_test.rb +++ b/test/output_at_test.rb @@ -134,4 +134,45 @@ class OutputAtTest < Test::Unit::TestCase end end + context "Multiple commands output every :reboot" do + setup do + @output = Whenever.cron \ + <<-file + every :reboot do + command "command_1" + command "command_2" + end + file + end + + should "output both commands @reboot" do + assert_match "@reboot command_1", @output + assert_match "@reboot command_2", @output + end + end + + context "Many different job types output every :day" do + setup do + @output = Whenever.cron \ + <<-file + set :path, '/your/path' + every :day do + rake "blah:blah" + runner "runner_1" + command "command_1" + runner "runner_2" + command "command_2" + end + file + end + + should "output all of the commands @daily" do + assert_match '@daily cd /your/path && RAILS_ENV=production /usr/bin/env rake blah:blah', @output + assert_match '@daily /your/path/script/runner -e production "runner_1"', @output + assert_match '@daily command_1', @output + assert_match '@daily /your/path/script/runner -e production "runner_2"', @output + assert_match '@daily command_2', @output + end + end + end