whenever 0.8.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.travis.yml +20 -7
  4. data/Appraisals +19 -0
  5. data/CHANGELOG.md +116 -3
  6. data/Gemfile +3 -3
  7. data/LICENSE +2 -2
  8. data/README.md +133 -32
  9. data/Rakefile +3 -10
  10. data/bin/whenever +3 -0
  11. data/bin/wheneverize +8 -5
  12. data/gemfiles/activesupport4.1.gemfile +7 -0
  13. data/gemfiles/activesupport4.2.gemfile +7 -0
  14. data/gemfiles/activesupport5.0.gemfile +7 -0
  15. data/gemfiles/activesupport5.1.gemfile +7 -0
  16. data/gemfiles/activesupport5.2.gemfile +7 -0
  17. data/lib/whenever/capistrano/v2/hooks.rb +8 -0
  18. data/lib/whenever/capistrano/{recipes.rb → v2/recipes.rb} +7 -13
  19. data/lib/whenever/capistrano/{support.rb → v2/support.rb} +12 -0
  20. data/lib/whenever/capistrano/v3/tasks/whenever.rake +56 -0
  21. data/lib/whenever/capistrano.rb +5 -6
  22. data/lib/whenever/command_line.rb +69 -48
  23. data/lib/whenever/cron.rb +54 -25
  24. data/lib/whenever/job.rb +13 -14
  25. data/lib/whenever/job_list.rb +54 -24
  26. data/lib/whenever/numeric.rb +13 -0
  27. data/lib/whenever/numeric_seconds.rb +48 -0
  28. data/lib/whenever/os.rb +7 -0
  29. data/lib/whenever/output_redirection.rb +1 -0
  30. data/lib/whenever/setup.rb +19 -15
  31. data/lib/whenever/version.rb +2 -2
  32. data/lib/whenever.rb +19 -14
  33. data/test/functional/command_line_test.rb +379 -243
  34. data/test/functional/output_at_test.rb +227 -249
  35. data/test/functional/output_default_defined_jobs_test.rb +251 -193
  36. data/test/functional/output_defined_job_test.rb +65 -91
  37. data/test/functional/output_env_test.rb +22 -26
  38. data/test/functional/output_jobs_for_roles_test.rb +46 -65
  39. data/test/functional/output_jobs_with_mailto_test.rb +168 -0
  40. data/test/functional/output_redirection_test.rb +232 -291
  41. data/test/test_case.rb +32 -0
  42. data/test/test_helper.rb +44 -15
  43. data/test/unit/capistrano_support_test.rb +128 -134
  44. data/test/unit/cron_test.rb +373 -208
  45. data/test/unit/executable_test.rb +142 -0
  46. data/test/unit/job_test.rb +111 -117
  47. data/whenever.gemspec +7 -4
  48. metadata +63 -44
@@ -1,268 +1,246 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
-
3
- class OutputAtTest < Test::Unit::TestCase
4
-
5
- context "weekday at a (single) given time" do
6
- setup do
7
- @output = Whenever.cron \
8
- <<-file
9
- set :job_template, nil
10
- every "weekday", :at => '5:02am' do
11
- command "blahblah"
12
- end
13
- file
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
- context "weekday at a multiple diverse times, via an array" do
22
- setup do
23
- @output = Whenever.cron \
24
- <<-file
25
- set :job_template, nil
26
- every "weekday", :at => %w(5:02am 3:52pm) do
27
- command "blahblah"
28
- end
29
- file
30
- end
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
- context "weekday at a multiple diverse times, comma separated" do
39
- setup do
40
- @output = Whenever.cron \
41
- <<-file
42
- set :job_template, nil
43
- every "weekday", :at => '5:02am, 3:52pm' do
44
- command "blahblah"
45
- end
46
- file
47
- end
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
- context "weekday at a multiple aligned times" do
56
- setup do
57
- @output = Whenever.cron \
58
- <<-file
59
- set :job_template, nil
60
- every "weekday", :at => '5:02am, 3:02pm' do
61
- command "blahblah"
62
- end
63
- file
64
- end
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
- context "various days at a various aligned times" do
72
- setup do
73
- @output = Whenever.cron \
74
- <<-file
75
- set :job_template, nil
76
- every "mon,wed,fri", :at => '5:02am, 3:02pm' do
77
- command "blahblah"
78
- end
79
- file
80
- end
81
-
82
- should "output the command using one entry because the times are aligned" do
83
- assert_match '2 5,15 * * 1,3,5 blahblah', @output
84
- end
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
- context "various days at a various aligned times using a runner" do
88
- setup do
89
- @output = Whenever.cron \
90
- <<-file
91
- set :job_template, nil
92
- set :path, '/your/path'
93
- every "mon,wed,fri", :at => '5:02am, 3:02pm' do
94
- runner "blahblah"
95
- end
96
- file
97
- end
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
- context "various days at a various aligned times using a rake task" do
105
- setup do
106
- @output = Whenever.cron \
107
- <<-file
108
- set :job_template, nil
109
- set :path, '/your/path'
110
- every "mon,wed,fri", :at => '5:02am, 3:02pm' do
111
- rake "blah:blah"
112
- end
113
- file
114
- end
115
-
116
- should "output the rake task using one entry because the times are aligned" do
117
- assert_match '2 5,15 * * 1,3,5 cd /your/path && RAILS_ENV=production bundle exec rake blah:blah --silent', @output
118
- end
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
- context "A command every 1.month at very diverse times" do
122
- setup do
123
- @output = Whenever.cron \
124
- <<-file
125
- set :job_template, nil
126
- every [1.month, 1.day], :at => 'january 5:02am, june 17th at 2:22pm, june 3rd at 3:33am' do
127
- command "blahblah"
128
- end
129
- file
130
- end
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
- context "Multiple commands output every :reboot" do
146
- setup do
147
- @output = Whenever.cron \
148
- <<-file
149
- set :job_template, nil
150
- every :reboot do
151
- command "command_1"
152
- command "command_2"
153
- end
154
- file
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
- context "Many different job types output every :day" do
164
- setup do
165
- @output = Whenever.cron \
166
- <<-file
167
- set :job_template, nil
168
- set :path, '/your/path'
169
- every :daily do
170
- rake "blah:blah"
171
- runner "runner_1"
172
- command "command_1"
173
- runner "runner_2"
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
- context "every 5 minutes but but starting at 1" do
189
- setup do
190
- @output = Whenever.cron \
191
- <<-file
192
- set :job_template, nil
193
- every 5.minutes, :at => 1 do
194
- command "blahblah"
195
- end
196
- file
197
- end
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
- context "every 4 minutes but starting at 2" do
205
- setup do
206
- @output = Whenever.cron \
207
- <<-file
208
- set :job_template, nil
209
- every 4.minutes, :at => 2 do
210
- command "blahblah"
211
- end
212
- file
213
- end
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
- context "every 3 minutes but starting at 7" do
221
- setup do
222
- @output = Whenever.cron \
223
- <<-file
224
- set :job_template, nil
225
- every 3.minutes, :at => 7 do
226
- command "blahblah"
227
- end
228
- file
229
- end
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
- context "every 2 minutes but starting at 27" do
237
- setup do
238
- @output = Whenever.cron \
239
- <<-file
240
- set :job_template, nil
241
- every 2.minutes, :at => 27 do
242
- command "blahblah"
243
- end
244
- file
245
- end
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
- context "using raw cron syntax" do
253
- setup do
254
- @output = Whenever.cron \
255
- <<-file
256
- set :job_template, nil
257
- every '0 0 27,31 * *' do
258
- command "blahblah"
259
- end
260
- file
261
- end
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