Allow the specification of an offset (using :at => [1-59]) when using

every( X.minutes ) { ... } for job definition. For example:

 every 5.minutes, :at => 1 do
          command "blahblah"
 end

produces

 1,6,11,16,21,26,31,36,41,46,51,56 * * * * blahblah
This commit is contained in:
Gerrit Riessen 2010-06-25 16:45:43 +08:00 committed by Javan Makhmali
parent f31148d27d
commit 087119ce2d
2 changed files with 60 additions and 1 deletions

View File

@ -77,7 +77,7 @@ module Whenever
raise ArgumentError, "Time must be in minutes or higher"
when 1.minute...1.hour
minute_frequency = @time / 60
timing[0] = comma_separated_timing(minute_frequency, 59)
timing[0] = comma_separated_timing(minute_frequency, 59, @at || 0)
when 1.hour...1.day
hour_frequency = (@time / 60 / 60).round
timing[0] = @at.is_a?(Time) ? @at.min : @at

View File

@ -175,4 +175,63 @@ class OutputAtTest < Test::Unit::TestCase
end
end
context "every 5 minutes but but starting at 1" do
setup do
@output = Whenever.cron \
<<-file
every 5.minutes, :at => 1 do
command "blahblah"
end
file
end
should "output the command using that time" do
assert_match '1,6,11,16,21,26,31,36,41,46,51,56 * * * * blahblah', @output
end
end
context "every 4 minutes but starting at 2" do
setup do
@output = Whenever.cron \
<<-file
every 4.minutes, :at => 2 do
command "blahblah"
end
file
end
should "output the command using that time" do
assert_match '2,6,10,14,18,22,26,30,34,38,42,46,50,54,58 * * * * blahblah', @output
end
end
context "every 3 minutes but starting at 7" do
setup do
@output = Whenever.cron \
<<-file
every 3.minutes, :at => 7 do
command "blahblah"
end
file
end
should "output the command using that time" do
assert_match '7,10,13,16,19,22,25,28,31,34,37,40,43,46,49,52,55,58 * * * * blahblah', @output
end
end
context "every 2 minutes but starting at 27" do
setup do
@output = Whenever.cron \
<<-file
every 2.minutes, :at => 27 do
command "blahblah"
end
file
end
should "output the command using that time" do
assert_match '27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59 * * * * blahblah', @output
end
end
end