resque-scheduler 2.5.5 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of resque-scheduler might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.gitignore +12 -6
- data/.rubocop.yml +18 -113
- data/.rubocop_todo.yml +29 -0
- data/.simplecov +3 -1
- data/.travis.yml +12 -4
- data/.vagrant-provision-as-vagrant.sh +15 -0
- data/.vagrant-provision.sh +23 -0
- data/.vagrant-skel/bash_profile +7 -0
- data/.vagrant-skel/bashrc +7 -0
- data/AUTHORS.md +5 -0
- data/Gemfile +1 -2
- data/HISTORY.md +18 -0
- data/README.md +39 -11
- data/ROADMAP.md +0 -6
- data/Rakefile +11 -19
- data/Vagrantfile +14 -0
- data/bin/resque-scheduler +2 -2
- data/examples/Rakefile +1 -1
- data/examples/config/initializers/resque-web.rb +2 -2
- data/examples/dynamic-scheduling/app/jobs/fix_schedules_job.rb +2 -4
- data/examples/dynamic-scheduling/app/jobs/send_email_job.rb +1 -1
- data/examples/dynamic-scheduling/app/models/user.rb +2 -2
- data/examples/dynamic-scheduling/lib/tasks/resque.rake +2 -2
- data/lib/resque-scheduler.rb +3 -1
- data/lib/resque/scheduler.rb +112 -168
- data/lib/resque/scheduler/cli.rb +144 -0
- data/lib/resque/scheduler/configuration.rb +73 -0
- data/lib/resque/scheduler/delaying_extensions.rb +278 -0
- data/lib/resque/scheduler/env.rb +61 -0
- data/lib/resque/scheduler/extension.rb +13 -0
- data/lib/resque/scheduler/lock.rb +2 -1
- data/lib/resque/scheduler/lock/base.rb +6 -2
- data/lib/resque/scheduler/lock/basic.rb +4 -5
- data/lib/resque/scheduler/lock/resilient.rb +30 -37
- data/lib/resque/scheduler/locking.rb +94 -0
- data/lib/resque/scheduler/logger_builder.rb +72 -0
- data/lib/resque/scheduler/plugin.rb +31 -0
- data/lib/resque/scheduler/scheduling_extensions.rb +150 -0
- data/lib/resque/scheduler/server.rb +246 -0
- data/lib/{resque_scheduler → resque/scheduler}/server/views/delayed.erb +2 -1
- data/lib/{resque_scheduler → resque/scheduler}/server/views/delayed_schedules.erb +0 -0
- data/lib/{resque_scheduler → resque/scheduler}/server/views/delayed_timestamp.erb +0 -0
- data/lib/{resque_scheduler → resque/scheduler}/server/views/requeue-params.erb +0 -0
- data/lib/{resque_scheduler → resque/scheduler}/server/views/scheduler.erb +16 -1
- data/lib/{resque_scheduler → resque/scheduler}/server/views/search.erb +2 -1
- data/lib/{resque_scheduler → resque/scheduler}/server/views/search_form.erb +0 -0
- data/lib/resque/scheduler/signal_handling.rb +40 -0
- data/lib/{resque_scheduler → resque/scheduler}/tasks.rb +3 -5
- data/lib/resque/scheduler/util.rb +41 -0
- data/lib/resque/scheduler/version.rb +7 -0
- data/resque-scheduler.gemspec +21 -19
- data/script/migrate_to_timestamps_set.rb +5 -3
- data/tasks/resque_scheduler.rake +1 -1
- data/test/cli_test.rb +26 -69
- data/test/delayed_queue_test.rb +262 -169
- data/test/env_test.rb +41 -0
- data/test/resque-web_test.rb +169 -48
- data/test/scheduler_args_test.rb +73 -41
- data/test/scheduler_hooks_test.rb +9 -8
- data/test/scheduler_locking_test.rb +55 -36
- data/test/scheduler_setup_test.rb +52 -15
- data/test/scheduler_task_test.rb +15 -10
- data/test/scheduler_test.rb +215 -114
- data/test/support/redis_instance.rb +32 -33
- data/test/test_helper.rb +33 -36
- data/test/util_test.rb +11 -0
- metadata +113 -57
- data/lib/resque/scheduler_locking.rb +0 -91
- data/lib/resque_scheduler.rb +0 -386
- data/lib/resque_scheduler/cli.rb +0 -160
- data/lib/resque_scheduler/logger_builder.rb +0 -72
- data/lib/resque_scheduler/plugin.rb +0 -28
- data/lib/resque_scheduler/server.rb +0 -183
- data/lib/resque_scheduler/util.rb +0 -34
- data/lib/resque_scheduler/version.rb +0 -5
- data/test/redis-test.conf +0 -108
data/test/env_test.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# vim:fileencoding=utf-8
|
2
|
+
require_relative 'test_helper'
|
3
|
+
|
4
|
+
context 'Env' do
|
5
|
+
def new_env(options = {})
|
6
|
+
Resque::Scheduler::Env.new(options)
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'daemonizes when background is true' do
|
10
|
+
Process.expects(:daemon)
|
11
|
+
env = new_env(background: true)
|
12
|
+
env.setup
|
13
|
+
end
|
14
|
+
|
15
|
+
test 'reconnects redis when background is true' do
|
16
|
+
Process.stubs(:daemon)
|
17
|
+
mock_redis_client = mock('redis_client')
|
18
|
+
mock_redis = mock('redis')
|
19
|
+
mock_redis.expects(:client).returns(mock_redis_client)
|
20
|
+
mock_redis_client.expects(:reconnect)
|
21
|
+
Resque.expects(:redis).returns(mock_redis)
|
22
|
+
env = new_env(background: true)
|
23
|
+
env.setup
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'aborts when background is given and Process does not support daemon' do
|
27
|
+
Process.stubs(:daemon)
|
28
|
+
Process.expects(:respond_to?).with('daemon').returns(false)
|
29
|
+
env = new_env(background: true)
|
30
|
+
env.expects(:abort)
|
31
|
+
env.setup
|
32
|
+
end
|
33
|
+
|
34
|
+
test 'writes pid to pidfile when given' do
|
35
|
+
mock_pidfile = mock('pidfile')
|
36
|
+
mock_pidfile.expects(:puts)
|
37
|
+
File.expects(:open).with('derp.pid', 'w').yields(mock_pidfile)
|
38
|
+
env = new_env(pidfile: 'derp.pid')
|
39
|
+
env.setup
|
40
|
+
end
|
41
|
+
end
|
data/test/resque-web_test.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
|
1
|
+
# vim:fileencoding=utf-8
|
2
|
+
require_relative 'test_helper'
|
2
3
|
|
3
|
-
|
4
|
-
require 'resque/server/test_helper.rb'
|
4
|
+
require 'resque/server/test_helper'
|
5
5
|
|
6
|
-
context
|
7
|
-
setup { get
|
6
|
+
context 'on GET to /schedule' do
|
7
|
+
setup { get '/schedule' }
|
8
8
|
|
9
|
-
|
9
|
+
test('is 200') { assert last_response.ok? }
|
10
10
|
end
|
11
11
|
|
12
|
-
context
|
12
|
+
context 'on GET to /schedule with scheduled jobs' do
|
13
13
|
setup do
|
14
14
|
Resque::Scheduler.env = 'production'
|
15
15
|
Resque.schedule = {
|
16
16
|
'some_ivar_job' => {
|
17
|
-
'cron' =>
|
17
|
+
'cron' => '* * * * *',
|
18
18
|
'class' => 'SomeIvarJob',
|
19
|
-
'args' =>
|
19
|
+
'args' => '/tmp',
|
20
20
|
'rails_env' => 'production'
|
21
21
|
},
|
22
22
|
'some_other_job' => {
|
23
|
-
'every' => ['
|
23
|
+
'every' => ['1m', ['1h']],
|
24
24
|
'queue' => 'high',
|
25
|
-
'
|
25
|
+
'custom_job_class' => 'SomeOtherJob',
|
26
26
|
'args' => {
|
27
27
|
'b' => 'blah'
|
28
28
|
}
|
@@ -33,13 +33,19 @@ context "on GET to /schedule with scheduled jobs" do
|
|
33
33
|
'class' => 'SomeFancyJob',
|
34
34
|
'args' => 'sparkles',
|
35
35
|
'rails_env' => 'fancy'
|
36
|
+
},
|
37
|
+
'shared_env_job' => {
|
38
|
+
'cron' => '* * * * *',
|
39
|
+
'class' => 'SomeSharedEnvJob',
|
40
|
+
'args' => '/tmp',
|
41
|
+
'rails_env' => 'fancy, production'
|
36
42
|
}
|
37
43
|
}
|
38
44
|
Resque::Scheduler.load_schedule!
|
39
|
-
get
|
45
|
+
get '/schedule'
|
40
46
|
end
|
41
47
|
|
42
|
-
|
48
|
+
test('is 200') { assert last_response.ok? }
|
43
49
|
|
44
50
|
test 'see the scheduled job' do
|
45
51
|
assert last_response.body.include?('SomeIvarJob')
|
@@ -48,22 +54,43 @@ context "on GET to /schedule with scheduled jobs" do
|
|
48
54
|
test 'excludes jobs for other envs' do
|
49
55
|
assert !last_response.body.include?('SomeFancyJob')
|
50
56
|
end
|
57
|
+
|
58
|
+
test 'includes job used in multiple environments' do
|
59
|
+
assert last_response.body.include?('SomeSharedEnvJob')
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'allows delete when dynamic' do
|
63
|
+
Resque::Scheduler.stubs(:dynamic).returns(true)
|
64
|
+
get '/schedule'
|
65
|
+
|
66
|
+
assert last_response.body.include?('Delete')
|
67
|
+
end
|
68
|
+
|
69
|
+
test "doesn't allow delete when static" do
|
70
|
+
Resque::Scheduler.stubs(:dynamic).returns(false)
|
71
|
+
get '/schedule'
|
72
|
+
|
73
|
+
assert !last_response.body.include?('Delete')
|
74
|
+
end
|
51
75
|
end
|
52
76
|
|
53
|
-
context
|
54
|
-
setup { get
|
77
|
+
context 'on GET to /delayed' do
|
78
|
+
setup { get '/delayed' }
|
55
79
|
|
56
|
-
|
80
|
+
test('is 200') { assert last_response.ok? }
|
57
81
|
end
|
58
82
|
|
59
|
-
context
|
83
|
+
context 'on GET to /delayed/jobs/:klass'do
|
60
84
|
setup do
|
61
85
|
@t = Time.now + 3600
|
62
86
|
Resque.enqueue_at(@t, SomeIvarJob, 'foo', 'bar')
|
63
|
-
get
|
87
|
+
get(
|
88
|
+
URI('/delayed/jobs/SomeIvarJob?args=' <<
|
89
|
+
URI.encode(%w(foo bar).to_json)).to_s
|
90
|
+
)
|
64
91
|
end
|
65
92
|
|
66
|
-
|
93
|
+
test('is 200') { assert last_response.ok? }
|
67
94
|
|
68
95
|
test 'see the scheduled job' do
|
69
96
|
assert last_response.body.include?(@t.to_s)
|
@@ -80,10 +107,13 @@ context "on GET to /delayed/jobs/:klass" do
|
|
80
107
|
end
|
81
108
|
end
|
82
109
|
Resque.enqueue_at(@t, Foo::Bar, 'foo', 'bar')
|
83
|
-
get
|
110
|
+
get(
|
111
|
+
URI('/delayed/jobs/Foo::Bar?args=' <<
|
112
|
+
URI.encode(%w(foo bar).to_json)).to_s
|
113
|
+
)
|
84
114
|
end
|
85
115
|
|
86
|
-
|
116
|
+
test('is 200') { assert last_response.ok? }
|
87
117
|
|
88
118
|
test 'see the scheduled job' do
|
89
119
|
assert last_response.body.include?(@t.to_s)
|
@@ -91,17 +121,18 @@ context "on GET to /delayed/jobs/:klass" do
|
|
91
121
|
end
|
92
122
|
end
|
93
123
|
|
94
|
-
|
95
|
-
{
|
124
|
+
module Test
|
125
|
+
RESQUE_SCHEDULE = {
|
96
126
|
'job_without_params' => {
|
97
127
|
'cron' => '* * * * *',
|
98
128
|
'class' => 'JobWithoutParams',
|
99
129
|
'args' => {
|
100
130
|
'host' => 'localhost'
|
101
131
|
},
|
102
|
-
'rails_env' => 'production'
|
132
|
+
'rails_env' => 'production'
|
133
|
+
},
|
103
134
|
'job_with_params' => {
|
104
|
-
'
|
135
|
+
'every' => '1m',
|
105
136
|
'class' => 'JobWithParams',
|
106
137
|
'args' => {
|
107
138
|
'host' => 'localhost'
|
@@ -116,20 +147,21 @@ def resque_schedule
|
|
116
147
|
}
|
117
148
|
end
|
118
149
|
|
119
|
-
context
|
150
|
+
context 'POST /schedule/requeue' do
|
120
151
|
setup do
|
121
|
-
Resque.schedule =
|
152
|
+
Resque.schedule = Test::RESQUE_SCHEDULE
|
122
153
|
Resque::Scheduler.load_schedule!
|
123
154
|
end
|
124
155
|
|
125
156
|
test 'job without params' do
|
126
157
|
# Regular jobs without params should redirect to /overview
|
127
158
|
job_name = 'job_without_params'
|
128
|
-
Resque::Scheduler.stubs(:enqueue_from_config)
|
159
|
+
Resque::Scheduler.stubs(:enqueue_from_config)
|
160
|
+
.once.with(Resque.schedule[job_name])
|
129
161
|
|
130
|
-
post '/schedule/requeue',
|
162
|
+
post '/schedule/requeue', 'job_name' => job_name
|
131
163
|
follow_redirect!
|
132
|
-
assert_equal
|
164
|
+
assert_equal 'http://example.org/overview', last_request.url
|
133
165
|
assert last_response.ok?
|
134
166
|
end
|
135
167
|
|
@@ -137,24 +169,30 @@ context "POST /schedule/requeue" do
|
|
137
169
|
# If a job has params defined,
|
138
170
|
# it should render the template with a form for the job params
|
139
171
|
job_name = 'job_with_params'
|
140
|
-
post '/schedule/requeue',
|
172
|
+
post '/schedule/requeue', 'job_name' => job_name
|
141
173
|
|
142
174
|
assert last_response.ok?, last_response.errors
|
143
|
-
assert last_response.body.include?(
|
144
|
-
assert last_response.body.include?(
|
175
|
+
assert last_response.body.include?('This job requires parameters')
|
176
|
+
assert last_response.body.include?(
|
177
|
+
%Q(<input type="hidden" name="job_name" value="#{job_name}">)
|
178
|
+
)
|
145
179
|
|
146
|
-
Resque.schedule[job_name]['parameters'].each do |
|
180
|
+
Resque.schedule[job_name]['parameters'].each do |_param_name, param_config|
|
147
181
|
assert last_response.body.include?(
|
148
|
-
|
182
|
+
'<span style="border-bottom:1px dotted;" ' <<
|
183
|
+
%Q[title="#{param_config['description']}">(?)</span>]
|
184
|
+
)
|
149
185
|
assert last_response.body.include?(
|
150
|
-
|
186
|
+
'<input type="text" name="log_level" ' <<
|
187
|
+
%Q(value="#{param_config['default']}">)
|
188
|
+
)
|
151
189
|
end
|
152
190
|
end
|
153
191
|
end
|
154
192
|
|
155
|
-
context
|
193
|
+
context 'POST /schedule/requeue_with_params' do
|
156
194
|
setup do
|
157
|
-
Resque.schedule =
|
195
|
+
Resque.schedule = Test::RESQUE_SCHEDULE
|
158
196
|
Resque::Scheduler.load_schedule!
|
159
197
|
end
|
160
198
|
|
@@ -168,18 +206,18 @@ context "POST /schedule/requeue_with_params" do
|
|
168
206
|
|
169
207
|
Resque::Scheduler.stubs(:enqueue_from_config).once.with(job_config)
|
170
208
|
|
171
|
-
post '/schedule/requeue_with_params',
|
172
|
-
|
173
|
-
|
174
|
-
|
209
|
+
post '/schedule/requeue_with_params',
|
210
|
+
'job_name' => job_name,
|
211
|
+
'log_level' => log_level
|
212
|
+
|
175
213
|
follow_redirect!
|
176
|
-
assert_equal
|
214
|
+
assert_equal 'http://example.org/overview', last_request.url
|
177
215
|
|
178
216
|
assert last_response.ok?, last_response.errors
|
179
217
|
end
|
180
218
|
end
|
181
219
|
|
182
|
-
context
|
220
|
+
context 'on POST to /delayed/search' do
|
183
221
|
setup do
|
184
222
|
t = Time.now + 60
|
185
223
|
Resque.enqueue_at(t, SomeIvarJob)
|
@@ -187,24 +225,107 @@ context "on POST to /delayed/search" do
|
|
187
225
|
end
|
188
226
|
|
189
227
|
test 'should find matching scheduled job' do
|
190
|
-
post
|
228
|
+
post '/delayed/search' , 'search' => 'ivar'
|
191
229
|
assert last_response.status == 200
|
192
230
|
assert last_response.body.include?('SomeIvarJob')
|
193
231
|
end
|
194
232
|
|
195
233
|
test 'should find matching queued job' do
|
196
|
-
post
|
234
|
+
post '/delayed/search' , 'search' => 'quick'
|
197
235
|
assert last_response.status == 200
|
198
236
|
assert last_response.body.include?('SomeQuickJob')
|
199
237
|
end
|
200
238
|
end
|
201
239
|
|
202
|
-
context
|
203
|
-
setup { post
|
240
|
+
context 'on POST to /delayed/cancel_now' do
|
241
|
+
setup { post '/delayed/cancel_now' }
|
204
242
|
|
205
243
|
test 'redirects to overview' do
|
206
244
|
assert last_response.status == 302
|
207
245
|
assert last_response.header['Location'].include? '/delayed'
|
208
246
|
end
|
247
|
+
end
|
248
|
+
|
249
|
+
context 'on POST to /delayed/clear' do
|
250
|
+
setup { post '/delayed/clear' }
|
251
|
+
|
252
|
+
test 'redirects to delayed' do
|
253
|
+
assert last_response.status == 302
|
254
|
+
assert last_response.header['Location'].include? '/delayed'
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
context 'on POST to /delayed/queue_now' do
|
259
|
+
setup { post '/delayed/queue_now' }
|
260
|
+
|
261
|
+
test 'redirects to overview' do
|
262
|
+
assert last_response.status == 302
|
263
|
+
assert last_response.header['Location'].include? '/overview'
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
context 'on GET to /delayed/:timestamp' do
|
268
|
+
setup { get '/delayed/1234567890' }
|
269
|
+
|
270
|
+
test 'shows delayed_timestamp view' do
|
271
|
+
assert last_response.status == 200
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
context 'DELETE /schedule when dynamic' do
|
276
|
+
setup do
|
277
|
+
Resque.schedule = Test::RESQUE_SCHEDULE
|
278
|
+
Resque::Scheduler.load_schedule!
|
279
|
+
Resque::Scheduler.stubs(:dynamic).returns(true)
|
280
|
+
end
|
281
|
+
|
282
|
+
test 'redirects to schedule page' do
|
283
|
+
delete '/schedule'
|
284
|
+
|
285
|
+
status = last_response.status
|
286
|
+
redirect_location = last_response.original_headers['Location']
|
287
|
+
response_status_msg = "Expected response to be a 302, but was a #{status}."
|
288
|
+
redirect_msg = "Redirect to #{redirect_location} instead of /schedule."
|
289
|
+
|
290
|
+
assert status == 302, response_status_msg
|
291
|
+
assert_match %r{/schedule/?$}, redirect_location, redirect_msg
|
292
|
+
end
|
293
|
+
|
294
|
+
test 'does not show the deleted job' do
|
295
|
+
delete '/schedule', job_name: 'job_with_params'
|
296
|
+
follow_redirect!
|
297
|
+
|
298
|
+
msg = 'The job should not have been shown on the /schedule page.'
|
299
|
+
assert !last_response.body.include?('job_with_params'), msg
|
300
|
+
end
|
209
301
|
|
302
|
+
test 'removes job from redis' do
|
303
|
+
delete '/schedule', job_name: 'job_with_params'
|
304
|
+
|
305
|
+
msg = 'The job was not deleted from redis.'
|
306
|
+
assert_nil Resque.fetch_schedule('job_with_params'), msg
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
context 'DELETE /schedule when static' do
|
311
|
+
setup do
|
312
|
+
Resque.schedule = Test::RESQUE_SCHEDULE
|
313
|
+
Resque::Scheduler.load_schedule!
|
314
|
+
Resque::Scheduler.stubs(:dynamic).returns(false)
|
315
|
+
end
|
316
|
+
|
317
|
+
test 'does not remove the job from the UI' do
|
318
|
+
delete '/schedule', job_name: 'job_with_params'
|
319
|
+
follow_redirect!
|
320
|
+
|
321
|
+
msg = 'The job should not have been removed from the /schedule page.'
|
322
|
+
assert last_response.body.include?('job_with_params'), msg
|
323
|
+
end
|
324
|
+
|
325
|
+
test 'does not remove job from redis' do
|
326
|
+
delete '/schedule', job_name: 'job_with_params'
|
327
|
+
|
328
|
+
msg = 'The job should not have been deleted from redis.'
|
329
|
+
assert Resque.fetch_schedule('job_with_params'), msg
|
330
|
+
end
|
210
331
|
end
|
data/test/scheduler_args_test.rb
CHANGED
@@ -1,31 +1,58 @@
|
|
1
|
-
|
1
|
+
# vim:fileencoding=utf-8
|
2
2
|
|
3
|
-
|
3
|
+
require_relative 'test_helper'
|
4
4
|
|
5
|
+
context 'scheduling jobs with arguments' do
|
5
6
|
setup do
|
6
7
|
Resque::Scheduler.clear_schedule!
|
7
|
-
Resque::Scheduler.
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
Resque::
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
Resque::Scheduler.enqueue_from_config(
|
8
|
+
Resque::Scheduler.configure do |c|
|
9
|
+
c.dynamic = false
|
10
|
+
c.quiet = true
|
11
|
+
c.poll_sleep_amount = nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
test 'enqueue_from_config puts stuff in resque without class loaded' do
|
16
|
+
Resque::Job.stubs(:create).once.returns(true)
|
17
|
+
.with('joes_queue', 'UndefinedJob', '/tmp')
|
18
|
+
Resque::Scheduler.enqueue_from_config(
|
19
|
+
'cron' => '* * * * *',
|
20
|
+
'class' => 'UndefinedJob',
|
21
|
+
'args' => '/tmp',
|
22
|
+
'queue' => 'joes_queue'
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'enqueue_from_config with_every_syntax' do
|
27
|
+
Resque::Job.stubs(:create).once.returns(true)
|
28
|
+
.with('james_queue', 'JamesJob', '/tmp')
|
29
|
+
Resque::Scheduler.enqueue_from_config(
|
30
|
+
'every' => '1m',
|
31
|
+
'class' => 'JamesJob',
|
32
|
+
'args' => '/tmp',
|
33
|
+
'queue' => 'james_queue'
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'enqueue_from_config puts jobs in the resque queue' do
|
38
|
+
Resque::Job.stubs(:create).once.returns(true)
|
39
|
+
.with(:ivar, SomeIvarJob, '/tmp')
|
40
|
+
Resque::Scheduler.enqueue_from_config(
|
41
|
+
'cron' => '* * * * *',
|
42
|
+
'class' => 'SomeIvarJob',
|
43
|
+
'args' => '/tmp'
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
test 'enqueue_from_config with custom_class_job in resque' do
|
48
|
+
FakeCustomJobClass.stubs(:scheduled).once.returns(true)
|
49
|
+
.with(:ivar, 'SomeIvarJob', '/tmp')
|
50
|
+
Resque::Scheduler.enqueue_from_config(
|
51
|
+
'cron' => '* * * * *',
|
52
|
+
'class' => 'SomeIvarJob',
|
53
|
+
'custom_job_class' => 'FakeCustomJobClass',
|
54
|
+
'args' => '/tmp'
|
55
|
+
)
|
29
56
|
end
|
30
57
|
|
31
58
|
test 'enqueue_from_config puts stuff in resque when env matches' do
|
@@ -100,24 +127,26 @@ context "scheduling jobs with arguments" do
|
|
100
127
|
assert_equal(1, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
101
128
|
end
|
102
129
|
|
103
|
-
test "calls the worker without arguments when 'args' is missing
|
130
|
+
test "calls the worker without arguments when 'args' is missing " \
|
131
|
+
'from the config' do
|
104
132
|
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
105
133
|
class: SomeIvarJob
|
106
134
|
YAML
|
107
|
-
SomeIvarJob.expects(:perform).once.with
|
135
|
+
SomeIvarJob.expects(:perform).once.with
|
108
136
|
Resque.reserve('ivar').perform
|
109
137
|
end
|
110
138
|
|
111
|
-
test "calls the worker without arguments when 'args' is blank
|
139
|
+
test "calls the worker without arguments when 'args' is blank " \
|
140
|
+
'in the config' do
|
112
141
|
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
113
142
|
class: SomeIvarJob
|
114
143
|
args:
|
115
144
|
YAML
|
116
|
-
SomeIvarJob.expects(:perform).once.with
|
145
|
+
SomeIvarJob.expects(:perform).once.with
|
117
146
|
Resque.reserve('ivar').perform
|
118
147
|
end
|
119
148
|
|
120
|
-
test
|
149
|
+
test 'calls the worker with a string when the config lists a string' do
|
121
150
|
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
122
151
|
class: SomeIvarJob
|
123
152
|
args: string
|
@@ -126,7 +155,7 @@ context "scheduling jobs with arguments" do
|
|
126
155
|
Resque.reserve('ivar').perform
|
127
156
|
end
|
128
157
|
|
129
|
-
test
|
158
|
+
test 'calls the worker with a Fixnum when the config lists an integer' do
|
130
159
|
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
131
160
|
class: SomeIvarJob
|
132
161
|
args: 1
|
@@ -135,7 +164,8 @@ context "scheduling jobs with arguments" do
|
|
135
164
|
Resque.reserve('ivar').perform
|
136
165
|
end
|
137
166
|
|
138
|
-
test
|
167
|
+
test 'calls the worker with multiple arguments when the config ' \
|
168
|
+
'lists an array' do
|
139
169
|
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
140
170
|
class: SomeIvarJob
|
141
171
|
args:
|
@@ -146,7 +176,8 @@ context "scheduling jobs with arguments" do
|
|
146
176
|
Resque.reserve('ivar').perform
|
147
177
|
end
|
148
178
|
|
149
|
-
test
|
179
|
+
test 'calls the worker with an array when the config lists ' \
|
180
|
+
'a nested array' do
|
150
181
|
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
151
182
|
class: SomeIvarJob
|
152
183
|
args:
|
@@ -157,7 +188,7 @@ context "scheduling jobs with arguments" do
|
|
157
188
|
Resque.reserve('ivar').perform
|
158
189
|
end
|
159
190
|
|
160
|
-
test
|
191
|
+
test 'calls the worker with a hash when the config lists a hash' do
|
161
192
|
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
162
193
|
class: SomeIvarJob
|
163
194
|
args:
|
@@ -167,24 +198,25 @@ context "scheduling jobs with arguments" do
|
|
167
198
|
Resque.reserve('ivar').perform
|
168
199
|
end
|
169
200
|
|
170
|
-
test
|
201
|
+
test 'calls the worker with a nested hash when the config lists ' \
|
202
|
+
'a nested hash' do
|
171
203
|
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
172
204
|
class: SomeIvarJob
|
173
205
|
args:
|
174
206
|
first_key:
|
175
207
|
second_key: value
|
176
208
|
YAML
|
177
|
-
SomeIvarJob.expects(:perform).once
|
209
|
+
SomeIvarJob.expects(:perform).once
|
210
|
+
.with('first_key' => { 'second_key' => 'value' })
|
178
211
|
Resque.reserve('ivar').perform
|
179
212
|
end
|
180
|
-
|
181
|
-
test
|
213
|
+
|
214
|
+
test 'poll_sleep_amount defaults to 5' do
|
182
215
|
assert_equal 5, Resque::Scheduler.poll_sleep_amount
|
183
216
|
end
|
184
|
-
|
185
|
-
test
|
217
|
+
|
218
|
+
test 'poll_sleep_amount is settable' do
|
186
219
|
Resque::Scheduler.poll_sleep_amount = 1
|
187
|
-
assert_equal 1, Resque::Scheduler.poll_sleep_amount
|
220
|
+
assert_equal 1, Resque::Scheduler.poll_sleep_amount
|
188
221
|
end
|
189
|
-
|
190
222
|
end
|