Allow multiple ":at" times, separated by commas

Signed-off-by: Javan Makhmali <javan@javan.us>
This commit is contained in:
Sam Ruby 2009-06-08 22:21:24 +08:00 committed by Javan Makhmali
parent 2bd1660386
commit abab2f8835
3 changed files with 53 additions and 8 deletions

View File

@ -94,12 +94,13 @@ module Whenever
output = []
@jobs.each do |time, jobs|
jobs.each do |job|
cron = Whenever::Output::Cron.output(time, job)
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
output.join
end

View File

@ -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

36
test/output_at_test.rb Normal file
View File

@ -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