mguymon-whenever 0.6.2
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.
- data/CHANGELOG.md +138 -0
- data/README.md +163 -0
- data/Rakefile +35 -0
- data/bin/whenever +38 -0
- data/bin/wheneverize +69 -0
- data/lib/whenever.rb +21 -0
- data/lib/whenever/capistrano.rb +33 -0
- data/lib/whenever/command_line.rb +125 -0
- data/lib/whenever/cron.rb +132 -0
- data/lib/whenever/job.rb +47 -0
- data/lib/whenever/job_list.rb +148 -0
- data/lib/whenever/output_redirection.rb +58 -0
- data/lib/whenever/setup.rb +18 -0
- data/lib/whenever/version.rb +3 -0
- data/mguymon-whenever.gemspec +83 -0
- data/test/functional/command_line_test.rb +310 -0
- data/test/functional/output_at_test.rb +251 -0
- data/test/functional/output_default_defined_jobs_test.rb +164 -0
- data/test/functional/output_defined_job_test.rb +111 -0
- data/test/functional/output_env_test.rb +23 -0
- data/test/functional/output_redirection_test.rb +307 -0
- data/test/test_helper.rb +20 -0
- data/test/unit/cron_test.rb +226 -0
- data/test/unit/job_test.rb +77 -0
- data/whenever.gemspec +85 -0
- metadata +132 -0
@@ -0,0 +1,251 @@
|
|
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
|
19
|
+
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
|
36
|
+
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
|
53
|
+
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
|
69
|
+
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
|
85
|
+
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
|
102
|
+
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 rake blah:blah --silent', @output
|
118
|
+
end
|
119
|
+
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
|
143
|
+
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
|
161
|
+
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 :day 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 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
|
186
|
+
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
|
202
|
+
end
|
203
|
+
|
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
|
218
|
+
end
|
219
|
+
|
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
|
234
|
+
end
|
235
|
+
|
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
|
250
|
+
end
|
251
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2
|
+
|
3
|
+
class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
# command
|
6
|
+
|
7
|
+
context "A plain command with the job template set to nil" do
|
8
|
+
setup do
|
9
|
+
@output = Whenever.cron \
|
10
|
+
<<-file
|
11
|
+
set :job_template, nil
|
12
|
+
every 2.hours do
|
13
|
+
command "blahblah"
|
14
|
+
end
|
15
|
+
file
|
16
|
+
end
|
17
|
+
|
18
|
+
should "output the command" do
|
19
|
+
assert_match /^.+ .+ .+ .+ blahblah$/, @output
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "A plain command with no job template set" do
|
24
|
+
setup do
|
25
|
+
@output = Whenever.cron \
|
26
|
+
<<-file
|
27
|
+
every 2.hours do
|
28
|
+
command "blahblah"
|
29
|
+
end
|
30
|
+
file
|
31
|
+
end
|
32
|
+
|
33
|
+
should "output the command with the default job template" do
|
34
|
+
assert_match /^.+ .+ .+ .+ \/bin\/bash -l -c 'blahblah'$/, @output
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "A plain command that overrides the job_template set" do
|
39
|
+
setup do
|
40
|
+
@output = Whenever.cron \
|
41
|
+
<<-file
|
42
|
+
set :job_template, "/bin/bash -l -c ':job'"
|
43
|
+
every 2.hours do
|
44
|
+
command "blahblah", :job_template => "/bin/sh -l -c ':job'"
|
45
|
+
end
|
46
|
+
file
|
47
|
+
end
|
48
|
+
|
49
|
+
should "output the command using that job_template" do
|
50
|
+
assert_match /^.+ .+ .+ .+ \/bin\/sh -l -c 'blahblah'$/, @output
|
51
|
+
assert_no_match /bash/, @output
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "A plain command that is conditional on default environent and path" do
|
56
|
+
setup do
|
57
|
+
Whenever.expects(:path).at_least_once.returns('/what/you/want')
|
58
|
+
@output = Whenever.cron \
|
59
|
+
<<-file
|
60
|
+
set :job_template, nil
|
61
|
+
if environment == 'production' && path == '/what/you/want'
|
62
|
+
every 2.hours do
|
63
|
+
command "blahblah"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
file
|
67
|
+
end
|
68
|
+
|
69
|
+
should "output the command" do
|
70
|
+
assert_match /blahblah/, @output
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# runner
|
75
|
+
|
76
|
+
context "A runner with path set" do
|
77
|
+
setup do
|
78
|
+
@output = Whenever.cron \
|
79
|
+
<<-file
|
80
|
+
set :job_template, nil
|
81
|
+
set :path, '/my/path'
|
82
|
+
every 2.hours do
|
83
|
+
runner 'blahblah'
|
84
|
+
end
|
85
|
+
file
|
86
|
+
end
|
87
|
+
|
88
|
+
should "output the runner using that path" do
|
89
|
+
assert_match two_hours + %( cd /my/path && script/runner -e production 'blahblah'), @output
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "A runner that overrides the path set" do
|
94
|
+
setup do
|
95
|
+
@output = Whenever.cron \
|
96
|
+
<<-file
|
97
|
+
set :job_template, nil
|
98
|
+
set :path, '/my/path'
|
99
|
+
every 2.hours do
|
100
|
+
runner "blahblah", :path => '/some/other/path'
|
101
|
+
end
|
102
|
+
file
|
103
|
+
end
|
104
|
+
|
105
|
+
should "output the runner using that path" do
|
106
|
+
assert_match two_hours + %( cd /some/other/path && script/runner -e production 'blahblah'), @output
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context "A runner for a Rails 3 app" do
|
111
|
+
setup do
|
112
|
+
Whenever.expects(:path).at_least_once.returns('/my/path')
|
113
|
+
File.expects(:exists?).with('/my/path/script/rails').returns(true)
|
114
|
+
@output = Whenever.cron \
|
115
|
+
<<-file
|
116
|
+
set :job_template, nil
|
117
|
+
every 2.hours do
|
118
|
+
runner 'blahblah'
|
119
|
+
end
|
120
|
+
file
|
121
|
+
end
|
122
|
+
|
123
|
+
should "use the Rails 3 runner job by default" do
|
124
|
+
assert_match two_hours + %( cd /my/path && script/rails runner -e production 'blahblah'), @output
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# rake
|
129
|
+
|
130
|
+
context "A rake command with path set" do
|
131
|
+
setup do
|
132
|
+
@output = Whenever.cron \
|
133
|
+
<<-file
|
134
|
+
set :job_template, nil
|
135
|
+
set :path, '/my/path'
|
136
|
+
every 2.hours do
|
137
|
+
rake "blahblah"
|
138
|
+
end
|
139
|
+
file
|
140
|
+
end
|
141
|
+
|
142
|
+
should "output the rake command using that path" do
|
143
|
+
assert_match two_hours + ' cd /my/path && RAILS_ENV=production rake blahblah --silent', @output
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context "A rake command that overrides the path set" do
|
148
|
+
setup do
|
149
|
+
@output = Whenever.cron \
|
150
|
+
<<-file
|
151
|
+
set :job_template, nil
|
152
|
+
set :path, '/my/path'
|
153
|
+
every 2.hours do
|
154
|
+
rake "blahblah", :path => '/some/other/path'
|
155
|
+
end
|
156
|
+
file
|
157
|
+
end
|
158
|
+
|
159
|
+
should "output the rake command using that path" do
|
160
|
+
assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production rake blahblah --silent', @output
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
2
|
+
|
3
|
+
class OutputDefinedJobTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "A defined job with a :task" do
|
6
|
+
setup do
|
7
|
+
@output = Whenever.cron \
|
8
|
+
<<-file
|
9
|
+
set :job_template, nil
|
10
|
+
job_type :some_job, "before :task after"
|
11
|
+
every 2.hours do
|
12
|
+
some_job "during"
|
13
|
+
end
|
14
|
+
file
|
15
|
+
end
|
16
|
+
|
17
|
+
should "output the defined job with the task" do
|
18
|
+
assert_match /^.+ .+ .+ .+ before during after$/, @output
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "A defined job with a :task and some options" do
|
23
|
+
setup do
|
24
|
+
@output = Whenever.cron \
|
25
|
+
<<-file
|
26
|
+
set :job_template, nil
|
27
|
+
job_type :some_job, "before :task after :option1 :option2"
|
28
|
+
every 2.hours do
|
29
|
+
some_job "during", :option1 => 'happy', :option2 => 'birthday'
|
30
|
+
end
|
31
|
+
file
|
32
|
+
end
|
33
|
+
|
34
|
+
should "output the defined job with the task and options" do
|
35
|
+
assert_match /^.+ .+ .+ .+ before during after happy birthday$/, @output
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "A defined job with a :task and an option where the option is set globally" do
|
40
|
+
setup do
|
41
|
+
@output = Whenever.cron \
|
42
|
+
<<-file
|
43
|
+
set :job_template, nil
|
44
|
+
job_type :some_job, "before :task after :option1"
|
45
|
+
set :option1, 'happy'
|
46
|
+
every 2.hours do
|
47
|
+
some_job "during"
|
48
|
+
end
|
49
|
+
file
|
50
|
+
end
|
51
|
+
|
52
|
+
should "output the defined job with the task and options" do
|
53
|
+
assert_match /^.+ .+ .+ .+ before during after happy$/, @output
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "A defined job with a :task and an option where the option is set globally and locally" do
|
58
|
+
setup do
|
59
|
+
@output = Whenever.cron \
|
60
|
+
<<-file
|
61
|
+
set :job_template, nil
|
62
|
+
job_type :some_job, "before :task after :option1"
|
63
|
+
set :option1, 'global'
|
64
|
+
every 2.hours do
|
65
|
+
some_job "during", :option1 => 'local'
|
66
|
+
end
|
67
|
+
file
|
68
|
+
end
|
69
|
+
|
70
|
+
should "output the defined job using the local option" do
|
71
|
+
assert_match /^.+ .+ .+ .+ before during after local$/, @output
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "A defined job with a :task and an option that is not set" do
|
76
|
+
setup do
|
77
|
+
@output = Whenever.cron \
|
78
|
+
<<-file
|
79
|
+
set :job_template, nil
|
80
|
+
job_type :some_job, "before :task after :option1"
|
81
|
+
every 2.hours do
|
82
|
+
some_job "during", :option2 => 'happy'
|
83
|
+
end
|
84
|
+
file
|
85
|
+
end
|
86
|
+
|
87
|
+
should "output the defined job with that option removed" do
|
88
|
+
assert_match /^.+ .+ .+ .+ before during after$/, @output
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "A defined job that uses a :path where none is explicitly set" do
|
93
|
+
setup do
|
94
|
+
Whenever.stubs(:path).returns('/my/path')
|
95
|
+
|
96
|
+
@output = Whenever.cron \
|
97
|
+
<<-file
|
98
|
+
set :job_template, nil
|
99
|
+
job_type :some_job, "cd :path && :task"
|
100
|
+
every 2.hours do
|
101
|
+
some_job 'blahblah'
|
102
|
+
end
|
103
|
+
file
|
104
|
+
end
|
105
|
+
|
106
|
+
should "default to using the Whenever.path" do
|
107
|
+
assert_match two_hours + %( cd /my/path && blahblah), @output
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|