diff --git a/lib/job_list.rb b/lib/job_list.rb index 245d7b8..e43b212 100644 --- a/lib/job_list.rb +++ b/lib/job_list.rb @@ -94,10 +94,11 @@ module Whenever output = [] @jobs.each do |time, jobs| jobs.each do |job| - cron = Whenever::Output::Cron.output(time, job) - cron << " >> #{job.cron_log} 2>&1" if job.cron_log - cron << "\n\n" - output << cron + Whenever::Output::Cron.output(time, job) do |cron| + cron << " >> #{job.cron_log} 2>&1" if job.cron_log + cron << "\n\n" + output << cron + end end end @@ -105,4 +106,4 @@ module Whenever end end -end \ No newline at end of file +end diff --git a/lib/outputs/cron.rb b/lib/outputs/cron.rb index 6394472..c770d32 100644 --- a/lib/outputs/cron.rb +++ b/lib/outputs/cron.rb @@ -12,8 +12,16 @@ module Whenever end def self.output(time, job) - out = new(time, job.output, job.at) - "#{out.time_in_cron_syntax} #{out.task}" + if job.at and job.at.is_a?(String) and !job.at.empty? + ats = job.at.split(',') + else + ats = [job.at] + end + + ats.each do |at| + out = new(time, job.output, at) + yield "#{out.time_in_cron_syntax} #{out.task}" + end end def time_in_cron_syntax @@ -114,4 +122,4 @@ module Whenever end end -end \ No newline at end of file +end diff --git a/test/output_at_test.rb b/test/output_at_test.rb new file mode 100644 index 0000000..d6f1ee1 --- /dev/null +++ b/test/output_at_test.rb @@ -0,0 +1,36 @@ +require File.expand_path(File.dirname(__FILE__) + "/test_helper") + +class OutputAtTest < Test::Unit::TestCase + + context "weekday at a (single) given time" do + setup do + @output = Whenever.cron \ + <<-file + every "weekday", :at=>'5:02am' do + command "blahblah" + end + file + end + + should "output the runner using that path" do + assert_match '2 5 * * mon-fri blahblah', @output + end + end + + context "weekday at a multiple diverse times" do + setup do + @output = Whenever.cron \ + <<-file + every "weekday", :at=>'5:02am, 3:52pm' do + command "blahblah" + end + file + end + + should "output the runner using that path" do + assert_match '2 5 * * mon-fri blahblah', @output + assert_match '52 15 * * mon-fri blahblah', @output + end + end + +end