allow raw cron sytanx

This commit is contained in:
Javan Makhmali 2011-03-06 17:31:17 -05:00
parent 6b69ebd10f
commit a94dda4b8b
4 changed files with 31 additions and 0 deletions

View File

@ -37,6 +37,10 @@ This will create an initial "config/schedule.rb" file you.
runner "Task.do_something_great" runner "Task.do_something_great"
end end
every '0 0 27-31 * *' do
command "echo 'you can use raw cron sytax too'"
end
More examples on the wiki: <http://wiki.github.com/javan/whenever/instructions-and-examples> More examples on the wiki: <http://wiki.github.com/javan/whenever/instructions-and-examples>
### Define your own job types ### Define your own job types

View File

@ -34,6 +34,7 @@ module Whenever
def time_in_cron_syntax def time_in_cron_syntax
case @time case @time
when /^.+ .+ .+ .+ .+.?$/ then @time # raw cron sytax given
when Symbol then parse_symbol when Symbol then parse_symbol
when String then parse_as_string when String then parse_as_string
else parse_time else parse_time

View File

@ -248,4 +248,21 @@ class OutputAtTest < Test::Unit::TestCase
assert_match '27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59 * * * * blahblah', @output assert_match '27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59 * * * * blahblah', @output
end end
end end
context "using raw cron syntax" do
setup do
@output = Whenever.cron \
<<-file
set :job_template, nil
every '0 0 27-31 * *' do
command "blahblah"
end
file
end
should "output the command using the same cron syntax" do
assert_match '0 0 27-31 * * blahblah', @output
end
end
end end

View File

@ -200,6 +200,15 @@ class CronTest < Test::Unit::TestCase
end end
end end
context "When given raw cron sytax" do
should "return the same cron sytax" do
crons = ['0 0 27-31 * *', '* * * * *', '2/3 1,9,22 11-26 1-6 *']
crons.each do |cron|
assert_equal cron, parse_time(cron)
end
end
end
private private
def assert_days_and_hours_and_minutes_equals(expected, time) def assert_days_and_hours_and_minutes_equals(expected, time)