whenever 0.5.3 → 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.rdoc → CHANGELOG.md} +35 -17
- data/README.md +139 -0
- data/Rakefile +2 -2
- data/bin/whenever +11 -8
- data/lib/whenever/capistrano.rb +31 -0
- data/lib/whenever/command_line.rb +3 -3
- data/lib/whenever/cron.rb +3 -8
- data/lib/whenever/job.rb +14 -8
- data/lib/whenever/job_list.rb +11 -24
- data/lib/whenever/output_redirection.rb +48 -50
- data/lib/whenever/setup.rb +18 -0
- data/lib/whenever/version.rb +1 -1
- data/lib/whenever.rb +13 -2
- data/test/functional/command_line_test.rb +10 -26
- data/test/functional/output_at_test.rb +16 -2
- data/test/functional/output_default_defined_jobs_test.rb +77 -3
- data/test/functional/output_defined_job_test.rb +7 -1
- data/test/functional/output_env_test.rb +0 -33
- data/test/functional/output_redirection_test.rb +18 -0
- data/test/unit/job_test.rb +17 -9
- data/whenever.gemspec +9 -9
- metadata +12 -12
- data/README.rdoc +0 -127
- data/lib/whenever/base.rb +0 -11
- data/lib/whenever/job_types/default.rb +0 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Environemnt defaults to production
|
|
2
|
+
set :environment, "production"
|
|
3
|
+
# Path defaults to the directory `whenever` was run from
|
|
4
|
+
set :path, Whenever.path
|
|
5
|
+
|
|
6
|
+
# All jobs are wrapped in this template.
|
|
7
|
+
# http://blog.scoutapp.com/articles/2010/09/07/rvm-and-cron-in-production
|
|
8
|
+
set :job_template, "/bin/bash -l -c ':job'"
|
|
9
|
+
|
|
10
|
+
job_type :command, ":task :output"
|
|
11
|
+
job_type :rake, "cd :path && RAILS_ENV=:environment rake :task --silent :output"
|
|
12
|
+
|
|
13
|
+
# Create a runner job that's appropriate for the Rails version,
|
|
14
|
+
if File.exists?(File.join(path, 'script', 'rails'))
|
|
15
|
+
job_type :runner, "cd :path && script/rails runner -e :environment ':task' :output"
|
|
16
|
+
else
|
|
17
|
+
job_type :runner, "cd :path && script/runner -e :environment ':task' :output"
|
|
18
|
+
end
|
data/lib/whenever/version.rb
CHANGED
data/lib/whenever.rb
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
require 'chronic'
|
|
2
2
|
require 'active_support/all'
|
|
3
3
|
|
|
4
|
-
require 'whenever/base'
|
|
5
4
|
require 'whenever/job_list'
|
|
6
5
|
require 'whenever/job'
|
|
7
6
|
require 'whenever/cron'
|
|
8
7
|
require 'whenever/output_redirection'
|
|
9
8
|
require 'whenever/command_line'
|
|
10
|
-
require 'whenever/version'
|
|
9
|
+
require 'whenever/version'
|
|
10
|
+
|
|
11
|
+
module Whenever
|
|
12
|
+
|
|
13
|
+
def self.cron(options)
|
|
14
|
+
Whenever::JobList.new(options).generate_cron_output
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.path
|
|
18
|
+
Dir.pwd
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -120,35 +120,18 @@ NEW_CRON
|
|
|
120
120
|
end
|
|
121
121
|
|
|
122
122
|
should "append the similarly named command" do
|
|
123
|
-
assert_equal @existing + "\n
|
|
123
|
+
assert_equal @existing + "\n" + @new, @command.send(:updated_crontab)
|
|
124
124
|
end
|
|
125
125
|
end
|
|
126
126
|
|
|
127
|
-
context "A command line
|
|
127
|
+
context "A command line clear" do
|
|
128
128
|
setup do
|
|
129
129
|
File.expects(:exists?).with('config/schedule.rb').returns(true)
|
|
130
130
|
@command = Whenever::CommandLine.new(:clear => true, :identifier => 'My identifier')
|
|
131
131
|
@task = "#{two_hours} /my/command"
|
|
132
132
|
end
|
|
133
133
|
|
|
134
|
-
should "
|
|
135
|
-
existing = '# Existing crontab'
|
|
136
|
-
@command.expects(:read_crontab).at_least_once.returns(existing)
|
|
137
|
-
|
|
138
|
-
new_cron = <<-EXPECTED
|
|
139
|
-
#{existing}
|
|
140
|
-
|
|
141
|
-
# Begin Whenever generated tasks for: My identifier
|
|
142
|
-
# End Whenever generated tasks for: My identifier
|
|
143
|
-
EXPECTED
|
|
144
|
-
|
|
145
|
-
assert_equal new_cron, @command.send(:updated_crontab)
|
|
146
|
-
|
|
147
|
-
@command.expects(:write_crontab).with(new_cron).returns(true)
|
|
148
|
-
assert @command.run
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
should "delete an existing block if the identifier matches" do
|
|
134
|
+
should "clear an existing block if the identifier matches" do
|
|
152
135
|
existing = <<-EXISTING_CRON
|
|
153
136
|
# Something
|
|
154
137
|
|
|
@@ -162,20 +145,17 @@ This shouldn't get replaced
|
|
|
162
145
|
EXISTING_CRON
|
|
163
146
|
|
|
164
147
|
@command.expects(:read_crontab).at_least_once.returns(existing)
|
|
165
|
-
|
|
148
|
+
|
|
166
149
|
new_cron = <<-NEW_CRON
|
|
167
150
|
# Something
|
|
168
151
|
|
|
169
|
-
# Begin Whenever generated tasks for: My identifier
|
|
170
|
-
# End Whenever generated tasks for: My identifier
|
|
171
|
-
|
|
172
152
|
# Begin Whenever generated tasks for: Other identifier
|
|
173
153
|
This shouldn't get replaced
|
|
174
154
|
# End Whenever generated tasks for: Other identifier
|
|
175
155
|
NEW_CRON
|
|
176
|
-
|
|
156
|
+
|
|
177
157
|
assert_equal new_cron, @command.send(:updated_crontab)
|
|
178
|
-
|
|
158
|
+
|
|
179
159
|
@command.expects(:write_crontab).with(new_cron).returns(true)
|
|
180
160
|
assert @command.run
|
|
181
161
|
end
|
|
@@ -217,6 +197,7 @@ NEW_CRON
|
|
|
217
197
|
setup do
|
|
218
198
|
@output = Whenever.cron :set => 'environment=serious', :string => \
|
|
219
199
|
<<-file
|
|
200
|
+
set :job_template, nil
|
|
220
201
|
set :environment, :silly
|
|
221
202
|
set :path, '/my/path'
|
|
222
203
|
every 2.hours do
|
|
@@ -234,6 +215,7 @@ NEW_CRON
|
|
|
234
215
|
setup do
|
|
235
216
|
@output = Whenever.cron :set => 'environment=serious&path=/serious/path', :string => \
|
|
236
217
|
<<-file
|
|
218
|
+
set :job_template, nil
|
|
237
219
|
set :environment, :silly
|
|
238
220
|
set :path, '/silly/path'
|
|
239
221
|
every 2.hours do
|
|
@@ -251,6 +233,7 @@ NEW_CRON
|
|
|
251
233
|
setup do
|
|
252
234
|
@output = Whenever.cron :set => ' environment = serious& path =/serious/path', :string => \
|
|
253
235
|
<<-file
|
|
236
|
+
set :job_template, nil
|
|
254
237
|
set :environment, :silly
|
|
255
238
|
set :path, '/silly/path'
|
|
256
239
|
every 2.hours do
|
|
@@ -268,6 +251,7 @@ NEW_CRON
|
|
|
268
251
|
setup do
|
|
269
252
|
@output = Whenever.cron :set => ' environment=', :string => \
|
|
270
253
|
<<-file
|
|
254
|
+
set :job_template, nil
|
|
271
255
|
set :environment, :silly
|
|
272
256
|
set :path, '/silly/path'
|
|
273
257
|
every 2.hours do
|
|
@@ -6,6 +6,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
6
6
|
setup do
|
|
7
7
|
@output = Whenever.cron \
|
|
8
8
|
<<-file
|
|
9
|
+
set :job_template, nil
|
|
9
10
|
every "weekday", :at => '5:02am' do
|
|
10
11
|
command "blahblah"
|
|
11
12
|
end
|
|
@@ -21,6 +22,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
21
22
|
setup do
|
|
22
23
|
@output = Whenever.cron \
|
|
23
24
|
<<-file
|
|
25
|
+
set :job_template, nil
|
|
24
26
|
every "weekday", :at => %w(5:02am 3:52pm) do
|
|
25
27
|
command "blahblah"
|
|
26
28
|
end
|
|
@@ -37,6 +39,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
37
39
|
setup do
|
|
38
40
|
@output = Whenever.cron \
|
|
39
41
|
<<-file
|
|
42
|
+
set :job_template, nil
|
|
40
43
|
every "weekday", :at => '5:02am, 3:52pm' do
|
|
41
44
|
command "blahblah"
|
|
42
45
|
end
|
|
@@ -53,6 +56,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
53
56
|
setup do
|
|
54
57
|
@output = Whenever.cron \
|
|
55
58
|
<<-file
|
|
59
|
+
set :job_template, nil
|
|
56
60
|
every "weekday", :at => '5:02am, 3:02pm' do
|
|
57
61
|
command "blahblah"
|
|
58
62
|
end
|
|
@@ -68,6 +72,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
68
72
|
setup do
|
|
69
73
|
@output = Whenever.cron \
|
|
70
74
|
<<-file
|
|
75
|
+
set :job_template, nil
|
|
71
76
|
every "mon,wed,fri", :at => '5:02am, 3:02pm' do
|
|
72
77
|
command "blahblah"
|
|
73
78
|
end
|
|
@@ -83,6 +88,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
83
88
|
setup do
|
|
84
89
|
@output = Whenever.cron \
|
|
85
90
|
<<-file
|
|
91
|
+
set :job_template, nil
|
|
86
92
|
set :path, '/your/path'
|
|
87
93
|
every "mon,wed,fri", :at => '5:02am, 3:02pm' do
|
|
88
94
|
runner "blahblah"
|
|
@@ -99,6 +105,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
99
105
|
setup do
|
|
100
106
|
@output = Whenever.cron \
|
|
101
107
|
<<-file
|
|
108
|
+
set :job_template, nil
|
|
102
109
|
set :path, '/your/path'
|
|
103
110
|
every "mon,wed,fri", :at => '5:02am, 3:02pm' do
|
|
104
111
|
rake "blah:blah"
|
|
@@ -107,7 +114,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
107
114
|
end
|
|
108
115
|
|
|
109
116
|
should "output the rake task using one entry because the times are aligned" do
|
|
110
|
-
assert_match '2 5,15 * * 1,3,5 cd /your/path && RAILS_ENV=production
|
|
117
|
+
assert_match '2 5,15 * * 1,3,5 cd /your/path && RAILS_ENV=production rake blah:blah --silent', @output
|
|
111
118
|
end
|
|
112
119
|
end
|
|
113
120
|
|
|
@@ -115,6 +122,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
115
122
|
setup do
|
|
116
123
|
@output = Whenever.cron \
|
|
117
124
|
<<-file
|
|
125
|
+
set :job_template, nil
|
|
118
126
|
every [1.month, 1.day], :at => 'january 5:02am, june 17th at 2:22pm, june 3rd at 3:33am' do
|
|
119
127
|
command "blahblah"
|
|
120
128
|
end
|
|
@@ -138,6 +146,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
138
146
|
setup do
|
|
139
147
|
@output = Whenever.cron \
|
|
140
148
|
<<-file
|
|
149
|
+
set :job_template, nil
|
|
141
150
|
every :reboot do
|
|
142
151
|
command "command_1"
|
|
143
152
|
command "command_2"
|
|
@@ -155,6 +164,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
155
164
|
setup do
|
|
156
165
|
@output = Whenever.cron \
|
|
157
166
|
<<-file
|
|
167
|
+
set :job_template, nil
|
|
158
168
|
set :path, '/your/path'
|
|
159
169
|
every :day do
|
|
160
170
|
rake "blah:blah"
|
|
@@ -167,7 +177,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
167
177
|
end
|
|
168
178
|
|
|
169
179
|
should "output all of the commands @daily" do
|
|
170
|
-
assert_match '@daily cd /your/path && RAILS_ENV=production
|
|
180
|
+
assert_match '@daily cd /your/path && RAILS_ENV=production rake blah:blah --silent', @output
|
|
171
181
|
assert_match %(@daily cd /your/path && script/runner -e production 'runner_1'), @output
|
|
172
182
|
assert_match '@daily command_1', @output
|
|
173
183
|
assert_match %(@daily cd /your/path && script/runner -e production 'runner_2'), @output
|
|
@@ -179,6 +189,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
179
189
|
setup do
|
|
180
190
|
@output = Whenever.cron \
|
|
181
191
|
<<-file
|
|
192
|
+
set :job_template, nil
|
|
182
193
|
every 5.minutes, :at => 1 do
|
|
183
194
|
command "blahblah"
|
|
184
195
|
end
|
|
@@ -194,6 +205,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
194
205
|
setup do
|
|
195
206
|
@output = Whenever.cron \
|
|
196
207
|
<<-file
|
|
208
|
+
set :job_template, nil
|
|
197
209
|
every 4.minutes, :at => 2 do
|
|
198
210
|
command "blahblah"
|
|
199
211
|
end
|
|
@@ -209,6 +221,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
209
221
|
setup do
|
|
210
222
|
@output = Whenever.cron \
|
|
211
223
|
<<-file
|
|
224
|
+
set :job_template, nil
|
|
212
225
|
every 3.minutes, :at => 7 do
|
|
213
226
|
command "blahblah"
|
|
214
227
|
end
|
|
@@ -224,6 +237,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
224
237
|
setup do
|
|
225
238
|
@output = Whenever.cron \
|
|
226
239
|
<<-file
|
|
240
|
+
set :job_template, nil
|
|
227
241
|
every 2.minutes, :at => 27 do
|
|
228
242
|
command "blahblah"
|
|
229
243
|
end
|
|
@@ -4,10 +4,11 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
|
|
4
4
|
|
|
5
5
|
# command
|
|
6
6
|
|
|
7
|
-
context "A plain command" do
|
|
7
|
+
context "A plain command with the job template set to nil" do
|
|
8
8
|
setup do
|
|
9
9
|
@output = Whenever.cron \
|
|
10
10
|
<<-file
|
|
11
|
+
set :job_template, nil
|
|
11
12
|
every 2.hours do
|
|
12
13
|
command "blahblah"
|
|
13
14
|
end
|
|
@@ -19,12 +20,64 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
|
|
19
20
|
end
|
|
20
21
|
end
|
|
21
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
|
+
|
|
22
74
|
# runner
|
|
23
75
|
|
|
24
76
|
context "A runner with path set" do
|
|
25
77
|
setup do
|
|
26
78
|
@output = Whenever.cron \
|
|
27
79
|
<<-file
|
|
80
|
+
set :job_template, nil
|
|
28
81
|
set :path, '/my/path'
|
|
29
82
|
every 2.hours do
|
|
30
83
|
runner 'blahblah'
|
|
@@ -41,6 +94,7 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
|
|
41
94
|
setup do
|
|
42
95
|
@output = Whenever.cron \
|
|
43
96
|
<<-file
|
|
97
|
+
set :job_template, nil
|
|
44
98
|
set :path, '/my/path'
|
|
45
99
|
every 2.hours do
|
|
46
100
|
runner "blahblah", :path => '/some/other/path'
|
|
@@ -53,12 +107,31 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
|
|
53
107
|
end
|
|
54
108
|
end
|
|
55
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
|
+
|
|
56
128
|
# rake
|
|
57
129
|
|
|
58
130
|
context "A rake command with path set" do
|
|
59
131
|
setup do
|
|
60
132
|
@output = Whenever.cron \
|
|
61
133
|
<<-file
|
|
134
|
+
set :job_template, nil
|
|
62
135
|
set :path, '/my/path'
|
|
63
136
|
every 2.hours do
|
|
64
137
|
rake "blahblah"
|
|
@@ -67,7 +140,7 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
|
|
67
140
|
end
|
|
68
141
|
|
|
69
142
|
should "output the rake command using that path" do
|
|
70
|
-
assert_match two_hours + ' cd /my/path && RAILS_ENV=production
|
|
143
|
+
assert_match two_hours + ' cd /my/path && RAILS_ENV=production rake blahblah --silent', @output
|
|
71
144
|
end
|
|
72
145
|
end
|
|
73
146
|
|
|
@@ -75,6 +148,7 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
|
|
75
148
|
setup do
|
|
76
149
|
@output = Whenever.cron \
|
|
77
150
|
<<-file
|
|
151
|
+
set :job_template, nil
|
|
78
152
|
set :path, '/my/path'
|
|
79
153
|
every 2.hours do
|
|
80
154
|
rake "blahblah", :path => '/some/other/path'
|
|
@@ -83,7 +157,7 @@ class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
|
|
83
157
|
end
|
|
84
158
|
|
|
85
159
|
should "output the rake command using that path" do
|
|
86
|
-
assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production
|
|
160
|
+
assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production rake blahblah --silent', @output
|
|
87
161
|
end
|
|
88
162
|
end
|
|
89
163
|
|
|
@@ -6,6 +6,7 @@ class OutputDefinedJobTest < Test::Unit::TestCase
|
|
|
6
6
|
setup do
|
|
7
7
|
@output = Whenever.cron \
|
|
8
8
|
<<-file
|
|
9
|
+
set :job_template, nil
|
|
9
10
|
job_type :some_job, "before :task after"
|
|
10
11
|
every 2.hours do
|
|
11
12
|
some_job "during"
|
|
@@ -22,6 +23,7 @@ class OutputDefinedJobTest < Test::Unit::TestCase
|
|
|
22
23
|
setup do
|
|
23
24
|
@output = Whenever.cron \
|
|
24
25
|
<<-file
|
|
26
|
+
set :job_template, nil
|
|
25
27
|
job_type :some_job, "before :task after :option1 :option2"
|
|
26
28
|
every 2.hours do
|
|
27
29
|
some_job "during", :option1 => 'happy', :option2 => 'birthday'
|
|
@@ -38,6 +40,7 @@ class OutputDefinedJobTest < Test::Unit::TestCase
|
|
|
38
40
|
setup do
|
|
39
41
|
@output = Whenever.cron \
|
|
40
42
|
<<-file
|
|
43
|
+
set :job_template, nil
|
|
41
44
|
job_type :some_job, "before :task after :option1"
|
|
42
45
|
set :option1, 'happy'
|
|
43
46
|
every 2.hours do
|
|
@@ -55,6 +58,7 @@ class OutputDefinedJobTest < Test::Unit::TestCase
|
|
|
55
58
|
setup do
|
|
56
59
|
@output = Whenever.cron \
|
|
57
60
|
<<-file
|
|
61
|
+
set :job_template, nil
|
|
58
62
|
job_type :some_job, "before :task after :option1"
|
|
59
63
|
set :option1, 'global'
|
|
60
64
|
every 2.hours do
|
|
@@ -72,6 +76,7 @@ class OutputDefinedJobTest < Test::Unit::TestCase
|
|
|
72
76
|
setup do
|
|
73
77
|
@output = Whenever.cron \
|
|
74
78
|
<<-file
|
|
79
|
+
set :job_template, nil
|
|
75
80
|
job_type :some_job, "before :task after :option1"
|
|
76
81
|
every 2.hours do
|
|
77
82
|
some_job "during", :option2 => 'happy'
|
|
@@ -86,10 +91,11 @@ class OutputDefinedJobTest < Test::Unit::TestCase
|
|
|
86
91
|
|
|
87
92
|
context "A defined job that uses a :path where none is explicitly set" do
|
|
88
93
|
setup do
|
|
89
|
-
Whenever.
|
|
94
|
+
Whenever.stubs(:path).returns('/my/path')
|
|
90
95
|
|
|
91
96
|
@output = Whenever.cron \
|
|
92
97
|
<<-file
|
|
98
|
+
set :job_template, nil
|
|
93
99
|
job_type :some_job, "cd :path && :task"
|
|
94
100
|
every 2.hours do
|
|
95
101
|
some_job 'blahblah'
|
|
@@ -19,38 +19,5 @@ class OutputEnvTest < Test::Unit::TestCase
|
|
|
19
19
|
assert_match "MAILTO=someone@example.com", @output
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
|
-
|
|
23
|
-
context "No PATH environment variable set" do
|
|
24
|
-
setup do
|
|
25
|
-
Whenever::JobList.any_instance.expects(:read_path).at_least_once.returns('/usr/local/bin')
|
|
26
|
-
@output = Whenever.cron ""
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
should "add a PATH variable based on the user's PATH" do
|
|
30
|
-
assert_match "PATH=/usr/local/bin", @output
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
context "A PATH environment variable set" do
|
|
35
|
-
setup do
|
|
36
|
-
Whenever::JobList.stubs(:read_path).returns('/usr/local/bin')
|
|
37
|
-
@output = Whenever.cron "env :PATH, '/my/path'"
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
should "use that path and the user's PATH" do
|
|
41
|
-
assert_match "PATH=/my/path", @output
|
|
42
|
-
assert_no_match /local/, @output
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
context "No PATH set and instructed not to automatically load the user's path" do
|
|
47
|
-
setup do
|
|
48
|
-
@output = Whenever.cron "set :set_path_automatically, false"
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
should "not have a PATH set" do
|
|
52
|
-
assert_no_match /PATH/, @output
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
22
|
|
|
56
23
|
end
|
|
@@ -6,6 +6,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
6
6
|
setup do
|
|
7
7
|
@output = Whenever.cron \
|
|
8
8
|
<<-file
|
|
9
|
+
set :job_template, nil
|
|
9
10
|
set :output, nil
|
|
10
11
|
every 2.hours do
|
|
11
12
|
command "blahblah"
|
|
@@ -23,6 +24,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
23
24
|
setup do
|
|
24
25
|
@output = Whenever.cron \
|
|
25
26
|
<<-file
|
|
27
|
+
set :job_template, nil
|
|
26
28
|
set :output, 'logfile.log'
|
|
27
29
|
every 2.hours do
|
|
28
30
|
command "blahblah"
|
|
@@ -39,6 +41,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
39
41
|
setup do
|
|
40
42
|
@output = Whenever.cron \
|
|
41
43
|
<<-file
|
|
44
|
+
set :job_template, nil
|
|
42
45
|
every 2.hours do
|
|
43
46
|
command "blahblah", :output => {:standard => 'dev_null', :error => 'dev_err'}
|
|
44
47
|
end
|
|
@@ -54,6 +57,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
54
57
|
setup do
|
|
55
58
|
@output = Whenever.cron \
|
|
56
59
|
<<-file
|
|
60
|
+
set :job_template, nil
|
|
57
61
|
set :output, 'logfile.log'
|
|
58
62
|
every 2.hours do
|
|
59
63
|
command "blahblah", :output => 'otherlog.log'
|
|
@@ -71,6 +75,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
71
75
|
setup do
|
|
72
76
|
@output = Whenever.cron \
|
|
73
77
|
<<-file
|
|
78
|
+
set :job_template, nil
|
|
74
79
|
set :output, 'logfile.log'
|
|
75
80
|
every 2.hours do
|
|
76
81
|
command "blahblah", :output => {:error => 'dev_err', :standard => 'dev_null' }
|
|
@@ -88,6 +93,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
88
93
|
setup do
|
|
89
94
|
@output = Whenever.cron \
|
|
90
95
|
<<-file
|
|
96
|
+
set :job_template, nil
|
|
91
97
|
set :output, 'logfile.log'
|
|
92
98
|
every 2.hours do
|
|
93
99
|
command "blahblah", :output => false
|
|
@@ -105,6 +111,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
105
111
|
setup do
|
|
106
112
|
@output = Whenever.cron :set => 'output=otherlog.log', :string => \
|
|
107
113
|
<<-file
|
|
114
|
+
set :job_template, nil
|
|
108
115
|
set :output, 'logfile.log'
|
|
109
116
|
every 2.hours do
|
|
110
117
|
command "blahblah"
|
|
@@ -122,6 +129,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
122
129
|
setup do
|
|
123
130
|
@output = Whenever.cron \
|
|
124
131
|
<<-file
|
|
132
|
+
set :job_template, nil
|
|
125
133
|
set :output, {:error => 'dev_err', :standard => 'dev_null' }
|
|
126
134
|
every 2.hours do
|
|
127
135
|
command "blahblah"
|
|
@@ -138,6 +146,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
138
146
|
setup do
|
|
139
147
|
@output = Whenever.cron \
|
|
140
148
|
<<-file
|
|
149
|
+
set :job_template, nil
|
|
141
150
|
set :output, {:error => 'dev_null'}
|
|
142
151
|
every 2.hours do
|
|
143
152
|
command "blahblah"
|
|
@@ -154,6 +163,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
154
163
|
setup do
|
|
155
164
|
@output = Whenever.cron \
|
|
156
165
|
<<-file
|
|
166
|
+
set :job_template, nil
|
|
157
167
|
set :output, {:standard => 'dev_out'}
|
|
158
168
|
every 2.hours do
|
|
159
169
|
command "blahblah"
|
|
@@ -170,6 +180,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
170
180
|
setup do
|
|
171
181
|
@output = Whenever.cron \
|
|
172
182
|
<<-file
|
|
183
|
+
set :job_template, nil
|
|
173
184
|
every 2.hours do
|
|
174
185
|
command "blahblah", :output => {:error => 'dev_err'}
|
|
175
186
|
end
|
|
@@ -185,6 +196,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
185
196
|
setup do
|
|
186
197
|
@output = Whenever.cron \
|
|
187
198
|
<<-file
|
|
199
|
+
set :job_template, nil
|
|
188
200
|
every 2.hours do
|
|
189
201
|
command "blahblah", :output => {:standard => 'dev_out'}
|
|
190
202
|
end
|
|
@@ -200,6 +212,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
200
212
|
setup do
|
|
201
213
|
@output = Whenever.cron \
|
|
202
214
|
<<-file
|
|
215
|
+
set :job_template, nil
|
|
203
216
|
every 2.hours do
|
|
204
217
|
command "blahblah", :output => {:standard => nil}
|
|
205
218
|
end
|
|
@@ -215,6 +228,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
215
228
|
setup do
|
|
216
229
|
@output = Whenever.cron \
|
|
217
230
|
<<-file
|
|
231
|
+
set :job_template, nil
|
|
218
232
|
every 2.hours do
|
|
219
233
|
command "blahblah", :output => {:error => nil}
|
|
220
234
|
end
|
|
@@ -230,6 +244,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
230
244
|
setup do
|
|
231
245
|
@output = Whenever.cron \
|
|
232
246
|
<<-file
|
|
247
|
+
set :job_template, nil
|
|
233
248
|
every 2.hours do
|
|
234
249
|
command "blahblah", :output => {:error => nil, :standard => nil}
|
|
235
250
|
end
|
|
@@ -245,6 +260,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
245
260
|
setup do
|
|
246
261
|
@output = Whenever.cron \
|
|
247
262
|
<<-file
|
|
263
|
+
set :job_template, nil
|
|
248
264
|
every 2.hours do
|
|
249
265
|
command "blahblah", :output => {:error => nil, :standard => 'my.log'}
|
|
250
266
|
end
|
|
@@ -260,6 +276,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
260
276
|
setup do
|
|
261
277
|
@output = Whenever.cron \
|
|
262
278
|
<<-file
|
|
279
|
+
set :job_template, nil
|
|
263
280
|
every 2.hours do
|
|
264
281
|
command "blahblah", :output => {:error => 'my_error.log', :standard => nil}
|
|
265
282
|
end
|
|
@@ -275,6 +292,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
275
292
|
setup do
|
|
276
293
|
@output = Whenever.cron \
|
|
277
294
|
<<-file
|
|
295
|
+
set :job_template, nil
|
|
278
296
|
set :cron_log, "cron.log"
|
|
279
297
|
every 2.hours do
|
|
280
298
|
command "blahblah"
|
data/test/unit/job_test.rb
CHANGED
|
@@ -7,14 +7,6 @@ class JobTest < Test::Unit::TestCase
|
|
|
7
7
|
assert_equal 'foo', new_job(:at => 'foo').at
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
should "return :output when #output_redirection is called" do
|
|
11
|
-
assert_equal 'foo', new_job(:output => 'foo').output_redirection
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
should "return :not_set when #output_redirection is called and no :output is set" do
|
|
15
|
-
assert_equal :not_set, new_job.output_redirection
|
|
16
|
-
end
|
|
17
|
-
|
|
18
10
|
should "substitute the :task when #output is called" do
|
|
19
11
|
job = new_job(:template => ":task", :task => 'abc123')
|
|
20
12
|
assert_equal 'abc123', job.output
|
|
@@ -32,7 +24,6 @@ class JobTest < Test::Unit::TestCase
|
|
|
32
24
|
|
|
33
25
|
|
|
34
26
|
context "A Job with quotes" do
|
|
35
|
-
|
|
36
27
|
should "output the :task if it's in single quotes" do
|
|
37
28
|
job = new_job(:template => "':task'", :task => 'abc123')
|
|
38
29
|
assert_equal %q('abc123'), job.output
|
|
@@ -59,6 +50,23 @@ class JobTest < Test::Unit::TestCase
|
|
|
59
50
|
assert_equal %q(before "quote -> \" <- quote" after), job.output
|
|
60
51
|
end
|
|
61
52
|
end
|
|
53
|
+
|
|
54
|
+
context "A Job with a job_template" do
|
|
55
|
+
should "use the job template" do
|
|
56
|
+
job = new_job(:template => ':task', :task => 'abc123', :job_template => 'left :job right')
|
|
57
|
+
assert_equal 'left abc123 right', job.output
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
should "escape single quotes" do
|
|
61
|
+
job = new_job(:template => "before ':task' after", :task => "quote -> ' <- quote", :job_template => "left ':job' right")
|
|
62
|
+
assert_equal %q(left 'before '\''quote -> '\\''\\'\\'''\\'' <- quote'\'' after' right), job.output
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
should "escape double quotes" do
|
|
66
|
+
job = new_job(:template => 'before ":task" after', :task => 'quote -> " <- quote', :job_template => 'left ":job" right')
|
|
67
|
+
assert_equal %q(left "before \"quote -> \\\" <- quote\" after" right), job.output
|
|
68
|
+
end
|
|
69
|
+
end
|
|
62
70
|
|
|
63
71
|
private
|
|
64
72
|
|