2010-09-06 17:18:39 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2009-06-08 14:21:24 +00:00
|
|
|
|
|
|
|
class OutputAtTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
context "weekday at a (single) given time" do
|
|
|
|
setup do
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
2010-10-20 21:12:00 +00:00
|
|
|
set :job_template, nil
|
2009-07-13 19:17:26 +00:00
|
|
|
every "weekday", :at => '5:02am' do
|
2009-06-08 14:21:24 +00:00
|
|
|
command "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
2009-07-13 19:17:26 +00:00
|
|
|
should "output the command using that time" do
|
2009-07-01 04:36:06 +00:00
|
|
|
assert_match '2 5 * * 1-5 blahblah', @output
|
2009-06-08 14:21:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-06-08 18:22:02 +00:00
|
|
|
context "weekday at a multiple diverse times, via an array" do
|
|
|
|
setup do
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
2010-10-20 21:12:00 +00:00
|
|
|
set :job_template, nil
|
2009-07-13 19:17:26 +00:00
|
|
|
every "weekday", :at => %w(5:02am 3:52pm) do
|
2009-06-08 18:22:02 +00:00
|
|
|
command "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
2009-07-13 19:17:26 +00:00
|
|
|
should "output the commands for both times given" do
|
2009-07-01 04:36:06 +00:00
|
|
|
assert_match '2 5 * * 1-5 blahblah', @output
|
|
|
|
assert_match '52 15 * * 1-5 blahblah', @output
|
2009-06-08 18:22:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "weekday at a multiple diverse times, comma separated" do
|
2009-06-08 14:21:24 +00:00
|
|
|
setup do
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
2010-10-20 21:12:00 +00:00
|
|
|
set :job_template, nil
|
2009-07-13 19:17:26 +00:00
|
|
|
every "weekday", :at => '5:02am, 3:52pm' do
|
2009-06-08 14:21:24 +00:00
|
|
|
command "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
2009-07-13 19:17:26 +00:00
|
|
|
should "output the commands for both times given" do
|
2009-07-01 04:36:06 +00:00
|
|
|
assert_match '2 5 * * 1-5 blahblah', @output
|
|
|
|
assert_match '52 15 * * 1-5 blahblah', @output
|
2009-06-08 14:21:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-06-08 18:22:02 +00:00
|
|
|
context "weekday at a multiple aligned times" do
|
|
|
|
setup do
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
2010-10-20 21:12:00 +00:00
|
|
|
set :job_template, nil
|
2009-07-13 19:17:26 +00:00
|
|
|
every "weekday", :at => '5:02am, 3:02pm' do
|
2009-06-08 18:22:02 +00:00
|
|
|
command "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
2009-07-13 19:17:26 +00:00
|
|
|
should "output the command using one entry because the times are aligned" do
|
2009-07-01 04:36:06 +00:00
|
|
|
assert_match '2 5,15 * * 1-5 blahblah', @output
|
2009-06-08 18:22:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "various days at a various aligned times" do
|
|
|
|
setup do
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
2010-10-20 21:12:00 +00:00
|
|
|
set :job_template, nil
|
2009-07-13 19:17:26 +00:00
|
|
|
every "mon,wed,fri", :at => '5:02am, 3:02pm' do
|
2009-06-08 18:22:02 +00:00
|
|
|
command "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
2009-07-13 19:17:26 +00:00
|
|
|
should "output the command using one entry because the times are aligned" do
|
2009-07-01 04:36:06 +00:00
|
|
|
assert_match '2 5,15 * * 1,3,5 blahblah', @output
|
2009-06-08 18:22:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-07-13 19:43:08 +00:00
|
|
|
context "various days at a various aligned times using a runner" do
|
|
|
|
setup do
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
2010-10-20 21:12:00 +00:00
|
|
|
set :job_template, nil
|
2009-07-13 19:43:08 +00:00
|
|
|
set :path, '/your/path'
|
|
|
|
every "mon,wed,fri", :at => '5:02am, 3:02pm' do
|
|
|
|
runner "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the runner using one entry because the times are aligned" do
|
2010-07-03 05:15:59 +00:00
|
|
|
assert_match %(2 5,15 * * 1,3,5 cd /your/path && script/runner -e production 'blahblah'), @output
|
2009-07-13 19:43:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "various days at a various aligned times using a rake task" do
|
|
|
|
setup do
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
2010-10-20 21:12:00 +00:00
|
|
|
set :job_template, nil
|
2009-07-13 19:43:08 +00:00
|
|
|
set :path, '/your/path'
|
|
|
|
every "mon,wed,fri", :at => '5:02am, 3:02pm' do
|
|
|
|
rake "blah:blah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output the rake task using one entry because the times are aligned" do
|
2010-10-18 14:41:00 +00:00
|
|
|
assert_match '2 5,15 * * 1,3,5 cd /your/path && RAILS_ENV=production rake blah:blah --silent', @output
|
2009-07-13 19:43:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-07-13 19:40:02 +00:00
|
|
|
context "A command every 1.month at very diverse times" do
|
|
|
|
setup do
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
2010-10-20 21:12:00 +00:00
|
|
|
set :job_template, nil
|
2009-11-30 19:34:58 +00:00
|
|
|
every [1.month, 1.day], :at => 'january 5:02am, june 17th at 2:22pm, june 3rd at 3:33am' do
|
2009-07-13 19:40:02 +00:00
|
|
|
command "blahblah"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output 6 commands since none align" do
|
|
|
|
# The 1.month commands
|
|
|
|
assert_match '2 5 1 * * blahblah', @output
|
|
|
|
assert_match '22 14 17 * * blahblah', @output
|
|
|
|
assert_match '33 3 3 * * blahblah', @output
|
|
|
|
|
|
|
|
# The 1.day commands
|
|
|
|
assert_match '2 5 * * * blahblah', @output
|
|
|
|
assert_match '22 14 * * * blahblah', @output
|
|
|
|
assert_match '33 3 * * * blahblah', @output
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-09-04 20:48:33 +00:00
|
|
|
context "Multiple commands output every :reboot" do
|
|
|
|
setup do
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
2010-10-20 21:12:00 +00:00
|
|
|
set :job_template, nil
|
2009-09-04 20:48:33 +00:00
|
|
|
every :reboot do
|
|
|
|
command "command_1"
|
|
|
|
command "command_2"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output both commands @reboot" do
|
|
|
|
assert_match "@reboot command_1", @output
|
|
|
|
assert_match "@reboot command_2", @output
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "Many different job types output every :day" do
|
|
|
|
setup do
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
2010-10-20 21:12:00 +00:00
|
|
|
set :job_template, nil
|
2009-09-04 20:48:33 +00:00
|
|
|
set :path, '/your/path'
|
2011-05-24 01:08:43 +00:00
|
|
|
every :daily do
|
2009-09-04 20:48:33 +00:00
|
|
|
rake "blah:blah"
|
|
|
|
runner "runner_1"
|
|
|
|
command "command_1"
|
|
|
|
runner "runner_2"
|
|
|
|
command "command_2"
|
|
|
|
end
|
|
|
|
file
|
|
|
|
end
|
|
|
|
|
|
|
|
should "output all of the commands @daily" do
|
2010-10-18 14:41:00 +00:00
|
|
|
assert_match '@daily cd /your/path && RAILS_ENV=production rake blah:blah --silent', @output
|
2010-07-03 05:15:59 +00:00
|
|
|
assert_match %(@daily cd /your/path && script/runner -e production 'runner_1'), @output
|
2009-09-04 20:48:33 +00:00
|
|
|
assert_match '@daily command_1', @output
|
2010-07-03 05:15:59 +00:00
|
|
|
assert_match %(@daily cd /your/path && script/runner -e production 'runner_2'), @output
|
2009-09-04 20:48:33 +00:00
|
|
|
assert_match '@daily command_2', @output
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
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
2010-06-25 08:45:43 +00:00
|
|
|
context "every 5 minutes but but starting at 1" do
|
|
|
|
setup do
|
|
|
|
@output = Whenever.cron \
|
|
|
|
<<-file
|
2010-10-20 21:12:00 +00:00
|
|
|
set :job_template, nil
|
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
2010-06-25 08:45:43 +00:00
|
|
|
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
|
2010-10-20 21:12:00 +00:00
|
|
|
set :job_template, nil
|
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
2010-06-25 08:45:43 +00:00
|
|
|
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
|
2010-10-20 21:12:00 +00:00
|
|
|
set :job_template, nil
|
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
2010-06-25 08:45:43 +00:00
|
|
|
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
|
2010-10-20 21:12:00 +00:00
|
|
|
set :job_template, nil
|
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
2010-06-25 08:45:43 +00:00
|
|
|
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
|
2011-03-06 22:31:17 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2009-06-08 14:21:24 +00:00
|
|
|
end
|