1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
|
require 'test_helper'
class OutputAtTest < Whenever::TestCase
test "weekday at a (single) given time" do
output = Whenever.cron \
<<-file
set :job_template, nil
every "weekday", :at => '5:02am' do
command "blahblah"
end
file
assert_match '2 5 * * 1-5 blahblah', output
end
test "weekday at a multiple diverse times, via an array" do
output = Whenever.cron \
<<-file
set :job_template, nil
every "weekday", :at => %w(5:02am 3:52pm) do
command "blahblah"
end
file
assert_match '2 5 * * 1-5 blahblah', output
assert_match '52 15 * * 1-5 blahblah', output
end
test "weekday at a multiple diverse times, comma separated" do
output = Whenever.cron \
<<-file
set :job_template, nil
every "weekday", :at => '5:02am, 3:52pm' do
command "blahblah"
end
file
assert_match '2 5 * * 1-5 blahblah', output
assert_match '52 15 * * 1-5 blahblah', output
end
test "weekday at a multiple aligned times" do
output = Whenever.cron \
<<-file
set :job_template, nil
every "weekday", :at => '5:02am, 3:02pm' do
command "blahblah"
end
file
assert_match '2 5,15 * * 1-5 blahblah', output
end
test "various days at a various aligned times" do
output = Whenever.cron \
<<-file
set :job_template, nil
every "mon,wed,fri", :at => '5:02am, 3:02pm' do
command "blahblah"
end
file
assert_match '2 5,15 * * 1,3,5 blahblah', output
end
test "various days at a various aligned times using a runner" do
output = Whenever.cron \
<<-file
set :job_template, nil
set :path, '/your/path'
every "mon,wed,fri", :at => '5:02am, 3:02pm' do
runner "Worker.perform_async(1.day.ago)"
end
file
assert_match %(2 5,15 * * 1,3,5 cd /your/path && bundle exec script/runner -e production 'Worker.perform_async(1.day.ago)'), output
end
test "various days at a various aligned times using a rake task" do
output = Whenever.cron \
<<-file
set :job_template, nil
set :path, '/your/path'
every "mon,wed,fri", :at => '5:02am, 3:02pm' do
rake "blah:blah"
end
file
assert_match '2 5,15 * * 1,3,5 cd /your/path && RAILS_ENV=production bundle exec rake blah:blah --silent', output
end
test "A command every 1.month at very diverse times" do
output = Whenever.cron \
<<-file
set :job_template, nil
every [1.month, 1.day], :at => 'january 5:02am, june 17th at 2:22pm, june 3rd at 3:33am' do
command "blahblah"
end
file
# 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
test "Multiple commands output every :reboot" do
output = Whenever.cron \
<<-file
set :job_template, nil
every :reboot do
command "command_1"
command "command_2"
end
file
assert_match "@reboot command_1", output
assert_match "@reboot command_2", output
end
test "Many different job types output every :day" do
output = Whenever.cron \
<<-file
set :job_template, nil
set :path, '/your/path'
every :daily do
rake "blah:blah"
runner "runner_1"
command "command_1"
runner "runner_2"
command "command_2"
end
file
assert_match '@daily cd /your/path && RAILS_ENV=production bundle exec rake blah:blah --silent', output
assert_match %(@daily cd /your/path && bundle exec script/runner -e production 'runner_1'), output
assert_match '@daily command_1', output
assert_match %(@daily cd /your/path && bundle exec script/runner -e production 'runner_2'), output
assert_match '@daily command_2', output
end
test "every 5 minutes but but starting at 1" do
output = Whenever.cron \
<<-file
set :job_template, nil
every 5.minutes, :at => 1 do
command "blahblah"
end
file
assert_match '1,6,11,16,21,26,31,36,41,46,51,56 * * * * blahblah', output
end
test "every 4 minutes but starting at 2" do
output = Whenever.cron \
<<-file
set :job_template, nil
every 4.minutes, :at => 2 do
command "blahblah"
end
file
assert_match '2,6,10,14,18,22,26,30,34,38,42,46,50,54,58 * * * * blahblah', output
end
test "every 3 minutes but starting at 7" do
output = Whenever.cron \
<<-file
set :job_template, nil
every 3.minutes, :at => 7 do
command "blahblah"
end
file
assert_match '7,10,13,16,19,22,25,28,31,34,37,40,43,46,49,52,55,58 * * * * blahblah', output
end
test "every 2 minutes but starting at 27" do
output = Whenever.cron \
<<-file
set :job_template, nil
every 2.minutes, :at => 27 do
command "blahblah"
end
file
assert_match '27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59 * * * * blahblah', output
end
test "using raw cron syntax" do
output = Whenever.cron \
<<-file
set :job_template, nil
every '0 0 27,31 * *' do
command "blahblah"
end
file
assert_match '0 0 27,31 * * blahblah', output
end
test "using custom Chronic configuration to specify time using 24 hour clock" do
output = Whenever.cron \
<<-file
set :job_template, nil
set :chronic_options, :hours24 => true
every 1.day, :at => '03:00' do
command "blahblah"
end
file
assert_match '0 3 * * * blahblah', output
end
test "using custom Chronic configuration to specify date using little endian preference" do
output = Whenever.cron \
<<-file
set :job_template, nil
set :chronic_options, :endian_precedence => :little
every 1.month, :at => '02/03 10:15' do
command "blahblah"
end
file
assert_match '15 10 2 * * blahblah', output
end
test "using custom Chronic configuration to specify time using 24 hour clock and date using little endian preference" do
output = Whenever.cron \
<<-file
set :job_template, nil
set :chronic_options, :hours24 => true, :endian_precedence => :little
every 1.month, :at => '01/02 04:30' do
command "blahblah"
end
file
assert_match '30 4 1 * * blahblah', output
end
end
|