whenever 0.8.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +20 -7
- data/Appraisals +19 -0
- data/CHANGELOG.md +116 -3
- data/Gemfile +3 -3
- data/LICENSE +2 -2
- data/README.md +133 -32
- data/Rakefile +3 -10
- data/bin/whenever +3 -0
- data/bin/wheneverize +8 -5
- data/gemfiles/activesupport4.1.gemfile +7 -0
- data/gemfiles/activesupport4.2.gemfile +7 -0
- data/gemfiles/activesupport5.0.gemfile +7 -0
- data/gemfiles/activesupport5.1.gemfile +7 -0
- data/gemfiles/activesupport5.2.gemfile +7 -0
- data/lib/whenever/capistrano/v2/hooks.rb +8 -0
- data/lib/whenever/capistrano/{recipes.rb → v2/recipes.rb} +7 -13
- data/lib/whenever/capistrano/{support.rb → v2/support.rb} +12 -0
- data/lib/whenever/capistrano/v3/tasks/whenever.rake +56 -0
- data/lib/whenever/capistrano.rb +5 -6
- data/lib/whenever/command_line.rb +69 -48
- data/lib/whenever/cron.rb +54 -25
- data/lib/whenever/job.rb +13 -14
- data/lib/whenever/job_list.rb +54 -24
- data/lib/whenever/numeric.rb +13 -0
- data/lib/whenever/numeric_seconds.rb +48 -0
- data/lib/whenever/os.rb +7 -0
- data/lib/whenever/output_redirection.rb +1 -0
- data/lib/whenever/setup.rb +19 -15
- data/lib/whenever/version.rb +2 -2
- data/lib/whenever.rb +19 -14
- data/test/functional/command_line_test.rb +379 -243
- data/test/functional/output_at_test.rb +227 -249
- data/test/functional/output_default_defined_jobs_test.rb +251 -193
- data/test/functional/output_defined_job_test.rb +65 -91
- data/test/functional/output_env_test.rb +22 -26
- data/test/functional/output_jobs_for_roles_test.rb +46 -65
- data/test/functional/output_jobs_with_mailto_test.rb +168 -0
- data/test/functional/output_redirection_test.rb +232 -291
- data/test/test_case.rb +32 -0
- data/test/test_helper.rb +44 -15
- data/test/unit/capistrano_support_test.rb +128 -134
- data/test/unit/cron_test.rb +373 -208
- data/test/unit/executable_test.rb +142 -0
- data/test/unit/job_test.rb +111 -117
- data/whenever.gemspec +7 -4
- metadata +63 -44
@@ -1,268 +1,246 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
class OutputAtTest <
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
should "output the command using that time" do
|
17
|
-
assert_match '2 5 * * 1-5 blahblah', @output
|
18
|
-
end
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class OutputAtTest < Whenever::TestCase
|
4
|
+
test "weekday at a (single) given time" do
|
5
|
+
output = Whenever.cron \
|
6
|
+
<<-file
|
7
|
+
set :job_template, nil
|
8
|
+
every "weekday", :at => '5:02am' do
|
9
|
+
command "blahblah"
|
10
|
+
end
|
11
|
+
file
|
12
|
+
|
13
|
+
assert_match '2 5 * * 1-5 blahblah', output
|
19
14
|
end
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
should "output the commands for both times given" do
|
33
|
-
assert_match '2 5 * * 1-5 blahblah', @output
|
34
|
-
assert_match '52 15 * * 1-5 blahblah', @output
|
35
|
-
end
|
15
|
+
|
16
|
+
test "weekday at a multiple diverse times, via an array" do
|
17
|
+
output = Whenever.cron \
|
18
|
+
<<-file
|
19
|
+
set :job_template, nil
|
20
|
+
every "weekday", :at => %w(5:02am 3:52pm) do
|
21
|
+
command "blahblah"
|
22
|
+
end
|
23
|
+
file
|
24
|
+
|
25
|
+
assert_match '2 5 * * 1-5 blahblah', output
|
26
|
+
assert_match '52 15 * * 1-5 blahblah', output
|
36
27
|
end
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
should "output the commands for both times given" do
|
50
|
-
assert_match '2 5 * * 1-5 blahblah', @output
|
51
|
-
assert_match '52 15 * * 1-5 blahblah', @output
|
52
|
-
end
|
28
|
+
|
29
|
+
test "weekday at a multiple diverse times, comma separated" do
|
30
|
+
output = Whenever.cron \
|
31
|
+
<<-file
|
32
|
+
set :job_template, nil
|
33
|
+
every "weekday", :at => '5:02am, 3:52pm' do
|
34
|
+
command "blahblah"
|
35
|
+
end
|
36
|
+
file
|
37
|
+
|
38
|
+
assert_match '2 5 * * 1-5 blahblah', output
|
39
|
+
assert_match '52 15 * * 1-5 blahblah', output
|
53
40
|
end
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
should "output the command using one entry because the times are aligned" do
|
67
|
-
assert_match '2 5,15 * * 1-5 blahblah', @output
|
68
|
-
end
|
41
|
+
|
42
|
+
test "weekday at a multiple aligned times" do
|
43
|
+
output = Whenever.cron \
|
44
|
+
<<-file
|
45
|
+
set :job_template, nil
|
46
|
+
every "weekday", :at => '5:02am, 3:02pm' do
|
47
|
+
command "blahblah"
|
48
|
+
end
|
49
|
+
file
|
50
|
+
|
51
|
+
assert_match '2 5,15 * * 1-5 blahblah', output
|
69
52
|
end
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
53
|
+
|
54
|
+
test "various days at a various aligned times" do
|
55
|
+
output = Whenever.cron \
|
56
|
+
<<-file
|
57
|
+
set :job_template, nil
|
58
|
+
every "mon,wed,fri", :at => '5:02am, 3:02pm' do
|
59
|
+
command "blahblah"
|
60
|
+
end
|
61
|
+
file
|
62
|
+
|
63
|
+
assert_match '2 5,15 * * 1,3,5 blahblah', output
|
64
|
+
end
|
65
|
+
|
66
|
+
test "various days at a various aligned times using a runner" do
|
67
|
+
output = Whenever.cron \
|
68
|
+
<<-file
|
69
|
+
set :job_template, nil
|
70
|
+
set :path, '/your/path'
|
71
|
+
every "mon,wed,fri", :at => '5:02am, 3:02pm' do
|
72
|
+
runner "Worker.perform_async(1.day.ago)"
|
73
|
+
end
|
74
|
+
file
|
75
|
+
|
76
|
+
assert_match %(2 5,15 * * 1,3,5 cd /your/path && bundle exec script/runner -e production 'Worker.perform_async(1.day.ago)'), output
|
77
|
+
end
|
78
|
+
|
79
|
+
test "various days at a various aligned times using a rake task" do
|
80
|
+
output = Whenever.cron \
|
81
|
+
<<-file
|
82
|
+
set :job_template, nil
|
83
|
+
set :path, '/your/path'
|
84
|
+
every "mon,wed,fri", :at => '5:02am, 3:02pm' do
|
85
|
+
rake "blah:blah"
|
86
|
+
end
|
87
|
+
file
|
88
|
+
|
89
|
+
assert_match '2 5,15 * * 1,3,5 cd /your/path && RAILS_ENV=production bundle exec rake blah:blah --silent', output
|
90
|
+
end
|
91
|
+
|
92
|
+
test "A command every 1.month at very diverse times" do
|
93
|
+
output = Whenever.cron \
|
94
|
+
<<-file
|
95
|
+
set :job_template, nil
|
96
|
+
every [1.month, 1.day], :at => 'january 5:02am, june 17th at 2:22pm, june 3rd at 3:33am' do
|
97
|
+
command "blahblah"
|
98
|
+
end
|
99
|
+
file
|
100
|
+
|
101
|
+
# The 1.month commands
|
102
|
+
assert_match '2 5 1 * * blahblah', output
|
103
|
+
assert_match '22 14 17 * * blahblah', output
|
104
|
+
assert_match '33 3 3 * * blahblah', output
|
105
|
+
|
106
|
+
# The 1.day commands
|
107
|
+
assert_match '2 5 * * * blahblah', output
|
108
|
+
assert_match '22 14 * * * blahblah', output
|
109
|
+
assert_match '33 3 * * * blahblah', output
|
85
110
|
end
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
should "output the runner using one entry because the times are aligned" do
|
100
|
-
assert_match %(2 5,15 * * 1,3,5 cd /your/path && script/runner -e production 'blahblah'), @output
|
101
|
-
end
|
111
|
+
|
112
|
+
test "Multiple commands output every :reboot" do
|
113
|
+
output = Whenever.cron \
|
114
|
+
<<-file
|
115
|
+
set :job_template, nil
|
116
|
+
every :reboot do
|
117
|
+
command "command_1"
|
118
|
+
command "command_2"
|
119
|
+
end
|
120
|
+
file
|
121
|
+
|
122
|
+
assert_match "@reboot command_1", output
|
123
|
+
assert_match "@reboot command_2", output
|
102
124
|
end
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
125
|
+
|
126
|
+
test "Many different job types output every :day" do
|
127
|
+
output = Whenever.cron \
|
128
|
+
<<-file
|
129
|
+
set :job_template, nil
|
130
|
+
set :path, '/your/path'
|
131
|
+
every :daily do
|
132
|
+
rake "blah:blah"
|
133
|
+
runner "runner_1"
|
134
|
+
command "command_1"
|
135
|
+
runner "runner_2"
|
136
|
+
command "command_2"
|
137
|
+
end
|
138
|
+
file
|
139
|
+
|
140
|
+
assert_match '@daily cd /your/path && RAILS_ENV=production bundle exec rake blah:blah --silent', output
|
141
|
+
assert_match %(@daily cd /your/path && bundle exec script/runner -e production 'runner_1'), output
|
142
|
+
assert_match '@daily command_1', output
|
143
|
+
assert_match %(@daily cd /your/path && bundle exec script/runner -e production 'runner_2'), output
|
144
|
+
assert_match '@daily command_2', output
|
119
145
|
end
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
should "output 6 commands since none align" do
|
133
|
-
# The 1.month commands
|
134
|
-
assert_match '2 5 1 * * blahblah', @output
|
135
|
-
assert_match '22 14 17 * * blahblah', @output
|
136
|
-
assert_match '33 3 3 * * blahblah', @output
|
137
|
-
|
138
|
-
# The 1.day commands
|
139
|
-
assert_match '2 5 * * * blahblah', @output
|
140
|
-
assert_match '22 14 * * * blahblah', @output
|
141
|
-
assert_match '33 3 * * * blahblah', @output
|
142
|
-
end
|
146
|
+
|
147
|
+
test "every 5 minutes but but starting at 1" do
|
148
|
+
output = Whenever.cron \
|
149
|
+
<<-file
|
150
|
+
set :job_template, nil
|
151
|
+
every 5.minutes, :at => 1 do
|
152
|
+
command "blahblah"
|
153
|
+
end
|
154
|
+
file
|
155
|
+
|
156
|
+
assert_match '1,6,11,16,21,26,31,36,41,46,51,56 * * * * blahblah', output
|
143
157
|
end
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
end
|
156
|
-
|
157
|
-
should "output both commands @reboot" do
|
158
|
-
assert_match "@reboot command_1", @output
|
159
|
-
assert_match "@reboot command_2", @output
|
160
|
-
end
|
158
|
+
|
159
|
+
test "every 4 minutes but starting at 2" do
|
160
|
+
output = Whenever.cron \
|
161
|
+
<<-file
|
162
|
+
set :job_template, nil
|
163
|
+
every 4.minutes, :at => 2 do
|
164
|
+
command "blahblah"
|
165
|
+
end
|
166
|
+
file
|
167
|
+
|
168
|
+
assert_match '2,6,10,14,18,22,26,30,34,38,42,46,50,54,58 * * * * blahblah', output
|
161
169
|
end
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
command "command_2"
|
175
|
-
end
|
176
|
-
file
|
177
|
-
end
|
178
|
-
|
179
|
-
should "output all of the commands @daily" do
|
180
|
-
assert_match '@daily cd /your/path && RAILS_ENV=production bundle exec rake blah:blah --silent', @output
|
181
|
-
assert_match %(@daily cd /your/path && script/runner -e production 'runner_1'), @output
|
182
|
-
assert_match '@daily command_1', @output
|
183
|
-
assert_match %(@daily cd /your/path && script/runner -e production 'runner_2'), @output
|
184
|
-
assert_match '@daily command_2', @output
|
185
|
-
end
|
170
|
+
|
171
|
+
test "every 3 minutes but starting at 7" do
|
172
|
+
output = Whenever.cron \
|
173
|
+
<<-file
|
174
|
+
set :job_template, nil
|
175
|
+
every 3.minutes, :at => 7 do
|
176
|
+
command "blahblah"
|
177
|
+
end
|
178
|
+
file
|
179
|
+
|
180
|
+
|
181
|
+
assert_match '7,10,13,16,19,22,25,28,31,34,37,40,43,46,49,52,55,58 * * * * blahblah', output
|
186
182
|
end
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
should "output the command using that time" do
|
200
|
-
assert_match '1,6,11,16,21,26,31,36,41,46,51,56 * * * * blahblah', @output
|
201
|
-
end
|
183
|
+
|
184
|
+
test "every 2 minutes but starting at 27" do
|
185
|
+
output = Whenever.cron \
|
186
|
+
<<-file
|
187
|
+
set :job_template, nil
|
188
|
+
every 2.minutes, :at => 27 do
|
189
|
+
command "blahblah"
|
190
|
+
end
|
191
|
+
file
|
192
|
+
|
193
|
+
assert_match '27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59 * * * * blahblah', output
|
202
194
|
end
|
203
195
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
should "output the command using that time" do
|
216
|
-
assert_match '2,6,10,14,18,22,26,30,34,38,42,46,50,54,58 * * * * blahblah', @output
|
217
|
-
end
|
196
|
+
test "using raw cron syntax" do
|
197
|
+
output = Whenever.cron \
|
198
|
+
<<-file
|
199
|
+
set :job_template, nil
|
200
|
+
every '0 0 27,31 * *' do
|
201
|
+
command "blahblah"
|
202
|
+
end
|
203
|
+
file
|
204
|
+
|
205
|
+
assert_match '0 0 27,31 * * blahblah', output
|
218
206
|
end
|
219
207
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
should "output the command using that time" do
|
232
|
-
assert_match '7,10,13,16,19,22,25,28,31,34,37,40,43,46,49,52,55,58 * * * * blahblah', @output
|
233
|
-
end
|
208
|
+
test "using custom Chronic configuration to specify time using 24 hour clock" do
|
209
|
+
output = Whenever.cron \
|
210
|
+
<<-file
|
211
|
+
set :job_template, nil
|
212
|
+
set :chronic_options, :hours24 => true
|
213
|
+
every 1.day, :at => '03:00' do
|
214
|
+
command "blahblah"
|
215
|
+
end
|
216
|
+
file
|
217
|
+
|
218
|
+
assert_match '0 3 * * * blahblah', output
|
234
219
|
end
|
235
220
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
should "output the command using that time" do
|
248
|
-
assert_match '27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59 * * * * blahblah', @output
|
249
|
-
end
|
221
|
+
test "using custom Chronic configuration to specify date using little endian preference" do
|
222
|
+
output = Whenever.cron \
|
223
|
+
<<-file
|
224
|
+
set :job_template, nil
|
225
|
+
set :chronic_options, :endian_precedence => :little
|
226
|
+
every 1.month, :at => '02/03 10:15' do
|
227
|
+
command "blahblah"
|
228
|
+
end
|
229
|
+
file
|
230
|
+
|
231
|
+
assert_match '15 10 2 * * blahblah', output
|
250
232
|
end
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
should "output the command using the same cron syntax" do
|
264
|
-
assert_match '0 0 27,31 * * blahblah', @output
|
265
|
-
end
|
233
|
+
|
234
|
+
test "using custom Chronic configuration to specify time using 24 hour clock and date using little endian preference" do
|
235
|
+
output = Whenever.cron \
|
236
|
+
<<-file
|
237
|
+
set :job_template, nil
|
238
|
+
set :chronic_options, :hours24 => true, :endian_precedence => :little
|
239
|
+
every 1.month, :at => '01/02 04:30' do
|
240
|
+
command "blahblah"
|
241
|
+
end
|
242
|
+
file
|
243
|
+
|
244
|
+
assert_match '30 4 1 * * blahblah', output
|
266
245
|
end
|
267
|
-
|
268
246
|
end
|