convert most shortcuts to seconds
This commit is contained in:
parent
a3b5791bbb
commit
1654f67774
@ -1,3 +1,8 @@
|
||||
### 0.6.8 / May 23rd, 2011
|
||||
|
||||
* Convert most shortcuts to seconds. every :day -> every 1.day. #129 [Javan Makhmali]
|
||||
|
||||
|
||||
### 0.6.7 / March 23rd, 2011
|
||||
|
||||
* Fix issue with comment block being corrupted during subsequent insertion of duplicate entries to the crontab. #123 [Jeremy (@lingmann)]
|
||||
|
@ -45,16 +45,25 @@ module Whenever
|
||||
|
||||
def parse_symbol
|
||||
shortcut = case @time
|
||||
when :reboot then '@reboot'
|
||||
when :year, :yearly then '@annually'
|
||||
when :day, :daily then '@daily'
|
||||
when :midnight then '@midnight'
|
||||
when :month, :monthly then '@monthly'
|
||||
when :week, :weekly then '@weekly'
|
||||
when :hour, :hourly then '@hourly'
|
||||
when :reboot then '@reboot'
|
||||
when :year then 12.months
|
||||
when :yearly,
|
||||
:annually then '@annually'
|
||||
when :day then 1.day
|
||||
when :daily then '@daily'
|
||||
when :midnight then '@midnight'
|
||||
when :month then 1.month
|
||||
when :monthly then '@monthly'
|
||||
when :week then 1.week
|
||||
when :weekly then '@weekly'
|
||||
when :hour then 1.hour
|
||||
when :hourly then '@hourly'
|
||||
end
|
||||
|
||||
if shortcut
|
||||
if shortcut.is_a?(Numeric)
|
||||
@time = shortcut
|
||||
parse_time
|
||||
elsif shortcut
|
||||
if @at.is_a?(Time) || (@at.is_a?(Numeric) && @at > 0)
|
||||
raise ArgumentError, "You cannot specify an ':at' when using the shortcuts for times."
|
||||
else
|
||||
|
@ -166,7 +166,7 @@ class OutputAtTest < Test::Unit::TestCase
|
||||
<<-file
|
||||
set :job_template, nil
|
||||
set :path, '/your/path'
|
||||
every :day do
|
||||
every :daily do
|
||||
rake "blah:blah"
|
||||
runner "runner_1"
|
||||
command "command_1"
|
||||
|
@ -174,20 +174,26 @@ class CronTest < Test::Unit::TestCase
|
||||
context "When parsing time using the cron shortcuts" do
|
||||
should "parse a :symbol into the correct shortcut" do
|
||||
assert_equal '@reboot', parse_time(:reboot)
|
||||
assert_equal '@annually', parse_time(:year)
|
||||
assert_equal '@annually', parse_time(:annually)
|
||||
assert_equal '@annually', parse_time(:yearly)
|
||||
assert_equal '@daily', parse_time(:day)
|
||||
assert_equal '@daily', parse_time(:daily)
|
||||
assert_equal '@midnight', parse_time(:midnight)
|
||||
assert_equal '@monthly', parse_time(:month)
|
||||
assert_equal '@monthly', parse_time(:monthly)
|
||||
assert_equal '@hourly', parse_time(:hour)
|
||||
assert_equal '@weekly', parse_time(:weekly)
|
||||
assert_equal '@hourly', parse_time(:hourly)
|
||||
end
|
||||
|
||||
should "convert time-based shortcuts to times" do
|
||||
assert_equal '0 0 1 * *', parse_time(:month)
|
||||
assert_equal '0 0 * * *', parse_time(:day)
|
||||
assert_equal '0 * * * *', parse_time(:hour)
|
||||
assert_equal '0 0 1 12 *', parse_time(:year)
|
||||
assert_equal '0 0 1,8,15,22 * *', parse_time(:week)
|
||||
end
|
||||
|
||||
should "raise an exception if a valid shortcut is given but also an :at" do
|
||||
assert_raises ArgumentError do
|
||||
parse_time(:hour, nil, "1:00 am")
|
||||
parse_time(:hourly, nil, "1:00 am")
|
||||
end
|
||||
|
||||
assert_raises ArgumentError do
|
||||
@ -195,7 +201,7 @@ class CronTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
assert_raises ArgumentError do
|
||||
parse_time(:day, nil, '4:20pm')
|
||||
parse_time(:daily, nil, '4:20pm')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user