resque-scheduler 4.2.1 → 4.5.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.

Files changed (60) hide show
  1. checksums.yaml +5 -5
  2. data/.github/dependabot.yml +12 -0
  3. data/.github/workflows/rubocop.yml +27 -0
  4. data/.github/workflows/ruby.yml +48 -0
  5. data/AUTHORS.md +7 -0
  6. data/CHANGELOG.md +495 -0
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/Gemfile +8 -0
  9. data/README.md +37 -17
  10. data/Rakefile +1 -5
  11. data/{bin → exe}/resque-scheduler +0 -0
  12. data/lib/resque/scheduler/cli.rb +1 -0
  13. data/lib/resque/scheduler/delaying_extensions.rb +38 -6
  14. data/lib/resque/scheduler/env.rb +8 -4
  15. data/lib/resque/scheduler/lock/resilient.rb +19 -12
  16. data/lib/resque/scheduler/locking.rb +2 -2
  17. data/lib/resque/scheduler/scheduling_extensions.rb +4 -3
  18. data/lib/resque/scheduler/server/views/delayed.erb +1 -1
  19. data/lib/resque/scheduler/server/views/search_form.erb +1 -1
  20. data/lib/resque/scheduler/server.rb +1 -1
  21. data/lib/resque/scheduler/version.rb +1 -1
  22. data/lib/resque/scheduler.rb +39 -16
  23. data/resque-scheduler.gemspec +29 -10
  24. metadata +62 -66
  25. data/.gitignore +0 -17
  26. data/.rubocop.yml +0 -18
  27. data/.rubocop_todo.yml +0 -71
  28. data/.simplecov +0 -3
  29. data/.travis.yml +0 -26
  30. data/.vagrant-provision-as-vagrant.sh +0 -15
  31. data/.vagrant-provision.sh +0 -23
  32. data/.vagrant-skel/bash_profile +0 -7
  33. data/.vagrant-skel/bashrc +0 -7
  34. data/HISTORY.md +0 -303
  35. data/Vagrantfile +0 -14
  36. data/examples/Rakefile +0 -2
  37. data/examples/config/initializers/resque-web.rb +0 -37
  38. data/examples/dynamic-scheduling/README.md +0 -28
  39. data/examples/dynamic-scheduling/app/jobs/fix_schedules_job.rb +0 -52
  40. data/examples/dynamic-scheduling/app/jobs/send_email_job.rb +0 -9
  41. data/examples/dynamic-scheduling/app/models/user.rb +0 -16
  42. data/examples/dynamic-scheduling/config/resque.yml +0 -4
  43. data/examples/dynamic-scheduling/config/static_schedule.yml +0 -7
  44. data/examples/dynamic-scheduling/lib/tasks/resque.rake +0 -48
  45. data/examples/run-resque-web +0 -3
  46. data/script/migrate_to_timestamps_set.rb +0 -16
  47. data/tasks/resque_scheduler.rake +0 -2
  48. data/test/cli_test.rb +0 -231
  49. data/test/delayed_queue_test.rb +0 -925
  50. data/test/env_test.rb +0 -47
  51. data/test/multi_process_test.rb +0 -125
  52. data/test/resque-web_test.rb +0 -364
  53. data/test/scheduler_args_test.rb +0 -222
  54. data/test/scheduler_hooks_test.rb +0 -55
  55. data/test/scheduler_locking_test.rb +0 -316
  56. data/test/scheduler_setup_test.rb +0 -141
  57. data/test/scheduler_task_test.rb +0 -72
  58. data/test/scheduler_test.rb +0 -473
  59. data/test/test_helper.rb +0 -147
  60. data/test/util_test.rb +0 -17
@@ -1,141 +0,0 @@
1
- # vim:fileencoding=utf-8
2
- require_relative 'test_helper'
3
-
4
- context 'Resque::Scheduler' do
5
- setup do
6
- ENV['VERBOSE'] = nil
7
- nullify_logger
8
- Resque::Scheduler.dynamic = false
9
- Resque.redis.flushall
10
- Resque::Scheduler.clear_schedule!
11
- end
12
-
13
- teardown { restore_devnull_logfile }
14
-
15
- test 'set custom logger' do
16
- custom_logger = MonoLogger.new('/dev/null')
17
- Resque::Scheduler.logger = custom_logger
18
-
19
- custom_logger.expects(:error).once
20
- Resque::Scheduler.log_error('test')
21
- end
22
-
23
- test 'custom logger is accessible' do
24
- custom_logger = MonoLogger.new('/dev/null')
25
- Resque::Scheduler.logger = custom_logger
26
-
27
- assert_equal custom_logger, Resque::Scheduler.logger
28
- end
29
-
30
- test 'configure block' do
31
- Resque::Scheduler.quiet = false
32
- Resque::Scheduler.configure do |c|
33
- c.quiet = true
34
- end
35
- assert_equal(Resque::Scheduler.quiet, true)
36
- end
37
-
38
- context 'when getting the env' do
39
- def wipe
40
- Resque::Scheduler.env = nil
41
- Rails.env = nil
42
- ENV['RAILS_ENV'] = nil
43
- end
44
-
45
- setup { wipe }
46
- teardown { wipe }
47
-
48
- test 'uses the value if set' do
49
- Resque::Scheduler.env = 'foo'
50
- assert_equal('foo', Resque::Scheduler.env)
51
- end
52
-
53
- test 'uses Rails.env if present' do
54
- Rails.env = 'bar'
55
- assert_equal('bar', Resque::Scheduler.env)
56
- end
57
-
58
- test 'uses $RAILS_ENV if present' do
59
- ENV['RAILS_ENV'] = 'baz'
60
- assert_equal('baz', Resque::Scheduler.env)
61
- end
62
- end
63
-
64
- context 'logger default settings' do
65
- setup { nullify_logger }
66
- teardown { restore_devnull_logfile }
67
-
68
- test 'uses STDOUT' do
69
- assert_equal(
70
- Resque::Scheduler.send(:logger)
71
- .instance_variable_get(:@logdev).dev, $stdout
72
- )
73
- end
74
-
75
- test 'not verbose' do
76
- assert Resque::Scheduler.send(:logger).level > MonoLogger::DEBUG
77
- end
78
-
79
- test 'not quieted' do
80
- assert Resque::Scheduler.send(:logger).level < MonoLogger::FATAL
81
- end
82
- end
83
-
84
- context 'logger custom settings' do
85
- setup { nullify_logger }
86
- teardown { restore_devnull_logfile }
87
-
88
- test 'uses logfile' do
89
- Resque::Scheduler.logfile = '/dev/null'
90
- assert_equal(
91
- Resque::Scheduler.send(:logger)
92
- .instance_variable_get(:@logdev).filename,
93
- '/dev/null'
94
- )
95
- end
96
-
97
- test 'set verbosity' do
98
- Resque::Scheduler.verbose = true
99
- assert Resque::Scheduler.send(:logger).level == MonoLogger::DEBUG
100
- end
101
-
102
- test 'quiet logger' do
103
- Resque::Scheduler.quiet = true
104
- assert Resque::Scheduler.send(:logger).level == MonoLogger::FATAL
105
- end
106
- end
107
-
108
- context 'logger with json formatter' do
109
- setup do
110
- nullify_logger
111
- Resque::Scheduler.logformat = 'json'
112
- $stdout = StringIO.new
113
- end
114
-
115
- teardown do
116
- $stdout = STDOUT
117
- end
118
-
119
- test 'logs with json' do
120
- Resque::Scheduler.log! 'whatever'
121
- assert $stdout.string =~ /"msg":"whatever"/
122
- end
123
- end
124
-
125
- context 'logger with text formatter' do
126
- setup do
127
- nullify_logger
128
- Resque::Scheduler.logformat = 'text'
129
- $stdout = StringIO.new
130
- end
131
-
132
- teardown do
133
- $stdout = STDOUT
134
- end
135
-
136
- test 'logs with text' do
137
- Resque::Scheduler.log! 'another thing'
138
- assert $stdout.string =~ /: another thing/
139
- end
140
- end
141
- end
@@ -1,72 +0,0 @@
1
- # vim:fileencoding=utf-8
2
- require_relative 'test_helper'
3
-
4
- context 'Resque::Scheduler' do
5
- setup do
6
- Resque::Scheduler.configure do |c|
7
- c.dynamic = false
8
- c.poll_sleep_amount = 0.1
9
- end
10
- Resque.redis.flushall
11
- Resque::Scheduler.quiet = true
12
- Resque::Scheduler.clear_schedule!
13
- Resque::Scheduler.send(:instance_variable_set, :@scheduled_jobs, {})
14
- Resque::Scheduler.send(:instance_variable_set, :@shutdown, false)
15
- end
16
-
17
- test 'shutdown raises Interrupt when sleeping' do
18
- Thread.current.expects(:raise).with(Interrupt)
19
- Resque::Scheduler.send(:instance_variable_set, :@th, Thread.current)
20
- Resque::Scheduler.send(:instance_variable_set, :@sleeping, true)
21
- Resque::Scheduler.shutdown
22
- end
23
-
24
- test 'sending TERM to scheduler breaks out of poll_sleep' do
25
- Resque::Scheduler.expects(:release_master_lock)
26
-
27
- @pid = Process.pid
28
- Thread.new do
29
- sleep(0.05)
30
- Process.kill(:TERM, @pid)
31
- end
32
-
33
- assert_raises SystemExit do
34
- Resque::Scheduler.run
35
- end
36
-
37
- Resque::Scheduler.unstub(:release_master_lock)
38
- Resque::Scheduler.release_master_lock
39
- end
40
-
41
- test 'can start successfully' do
42
- Resque::Scheduler.poll_sleep_amount = nil
43
-
44
- @pid = Process.pid
45
- Thread.new do
46
- sleep(0.15)
47
- Process.kill(:TERM, @pid)
48
- end
49
-
50
- assert_raises SystemExit do
51
- Resque::Scheduler.run
52
- end
53
- end
54
-
55
- test 'sending TERM to scheduler breaks out when poll_sleep_amount = 0' do
56
- Resque::Scheduler.poll_sleep_amount = 0
57
- Resque::Scheduler.expects(:release_master_lock)
58
-
59
- @pid = Process.pid
60
- Thread.new do
61
- sleep(0.05)
62
- Process.kill(:TERM, @pid)
63
- end
64
-
65
- assert_raises SystemExit do
66
- Resque::Scheduler.run
67
- end
68
-
69
- Resque::Scheduler.unstub(:release_master_lock)
70
- Resque::Scheduler.release_master_lock
71
- end
72
- end
@@ -1,473 +0,0 @@
1
- # vim:fileencoding=utf-8
2
- require_relative 'test_helper'
3
-
4
- context 'Resque::Scheduler' do
5
- setup do
6
- Resque::Scheduler.configure do |c|
7
- c.dynamic = false
8
- c.quiet = true
9
- c.env = nil
10
- c.app_name = nil
11
- end
12
- Resque.redis.flushall
13
- Resque::Scheduler.clear_schedule!
14
- Resque::Scheduler.send(:instance_variable_set, :@scheduled_jobs, {})
15
- end
16
-
17
- test 'enqueue constantizes' do
18
- Resque::Scheduler.env = 'production'
19
- config = {
20
- 'cron' => '* * * * *',
21
- 'class' => 'SomeRealClass',
22
- 'args' => '/tmp'
23
- }
24
- Resque::Job.expects(:create).with(
25
- SomeRealClass.queue, SomeRealClass, '/tmp'
26
- )
27
- Resque::Scheduler.enqueue_from_config(config)
28
- end
29
-
30
- test 'enqueue runs hooks' do
31
- Resque::Scheduler.env = 'production'
32
- config = {
33
- 'cron' => '* * * * *',
34
- 'class' => 'SomeJobWithResqueHooks',
35
- 'args' => '/tmp'
36
- }
37
-
38
- Resque::Job.expects(:create).with(
39
- SomeJobWithResqueHooks.queue, SomeJobWithResqueHooks, '/tmp'
40
- )
41
- SomeJobWithResqueHooks.expects(:before_delayed_enqueue_example).with('/tmp')
42
- SomeJobWithResqueHooks.expects(:before_enqueue_example).with('/tmp')
43
- SomeJobWithResqueHooks.expects(:after_enqueue_example).with('/tmp')
44
-
45
- Resque::Scheduler.enqueue_from_config(config)
46
- end
47
-
48
- test 'enqueue_from_config respects queue params' do
49
- config = {
50
- 'cron' => '* * * * *',
51
- 'class' => 'SomeIvarJob',
52
- 'queue' => 'high'
53
- }
54
- Resque.expects(:enqueue_to).with('high', SomeIvarJob)
55
- Resque::Scheduler.enqueue_from_config(config)
56
- end
57
-
58
- test 'config makes it into the rufus_scheduler' do
59
- assert_equal(0, Resque::Scheduler.rufus_scheduler.jobs.size)
60
-
61
- Resque.schedule = {
62
- 'some_ivar_job' => {
63
- 'cron' => '* * * * *',
64
- 'class' => 'SomeIvarJob',
65
- 'args' => '/tmp'
66
- }
67
- }
68
- Resque::Scheduler.load_schedule!
69
-
70
- assert_equal(1, Resque::Scheduler.rufus_scheduler.jobs.size)
71
- assert Resque::Scheduler.scheduled_jobs.include?('some_ivar_job')
72
- end
73
-
74
- test 'can reload schedule' do
75
- Resque::Scheduler.dynamic = true
76
- Resque.schedule = {
77
- 'some_ivar_job' => {
78
- 'cron' => '* * * * *',
79
- 'class' => 'SomeIvarJob',
80
- 'args' => '/tmp'
81
- }
82
- }
83
-
84
- Resque::Scheduler.load_schedule!
85
-
86
- assert_equal(1, Resque::Scheduler.rufus_scheduler.jobs.size)
87
- assert Resque::Scheduler.scheduled_jobs.include?('some_ivar_job')
88
-
89
- Resque.redis.del(:schedules)
90
- Resque.schedule = {
91
- 'some_ivar_job2' => {
92
- 'cron' => '* * * * *',
93
- 'class' => 'SomeIvarJob',
94
- 'args' => '/tmp/2'
95
- }
96
- }
97
-
98
- Resque::Scheduler.reload_schedule!
99
-
100
- assert_equal(1, Resque::Scheduler.rufus_scheduler.jobs.size)
101
-
102
- assert_equal '/tmp/2', Resque.schedule['some_ivar_job2']['args']
103
- assert Resque::Scheduler.scheduled_jobs.include?('some_ivar_job2')
104
- end
105
-
106
- test 'load_schedule_job loads a schedule' do
107
- Resque::Scheduler.load_schedule_job(
108
- 'some_ivar_job',
109
- 'cron' => '* * * * *',
110
- 'class' => 'SomeIvarJob',
111
- 'args' => '/tmp'
112
- )
113
-
114
- assert_equal(1, Resque::Scheduler.rufus_scheduler.jobs.size)
115
- assert_equal(1, Resque::Scheduler.scheduled_jobs.size)
116
- assert Resque::Scheduler.scheduled_jobs.keys.include?('some_ivar_job')
117
- end
118
-
119
- test 'load_schedule_job with every with options' do
120
- Resque::Scheduler.load_schedule_job(
121
- 'some_ivar_job',
122
- 'every' => ['30s', { 'first_in' => '60s' }],
123
- 'class' => 'SomeIvarJob',
124
- 'args' => '/tmp'
125
- )
126
-
127
- assert_equal(1, Resque::Scheduler.rufus_scheduler.jobs.size)
128
- assert_equal(1, Resque::Scheduler.scheduled_jobs.size)
129
- assert Resque::Scheduler.scheduled_jobs.keys.include?('some_ivar_job')
130
- job = Resque::Scheduler.scheduled_jobs['some_ivar_job']
131
- assert job.opts.keys.include?(:first_in)
132
- end
133
-
134
- test 'load_schedule_job with cron with options' do
135
- Resque::Scheduler.load_schedule_job(
136
- 'some_ivar_job',
137
- 'cron' => ['* * * * *', { 'allow_overlapping' => 'true' }],
138
- 'class' => 'SomeIvarJob',
139
- 'args' => '/tmp'
140
- )
141
-
142
- assert_equal(1, Resque::Scheduler.rufus_scheduler.jobs.size)
143
- assert_equal(1, Resque::Scheduler.scheduled_jobs.size)
144
- assert Resque::Scheduler.scheduled_jobs.keys.include?('some_ivar_job')
145
- job = Resque::Scheduler.scheduled_jobs['some_ivar_job']
146
- assert job.opts.keys.include?(:allow_overlapping)
147
- end
148
-
149
- test 'load_schedule_job without cron' do
150
- Resque::Scheduler.load_schedule_job(
151
- 'some_ivar_job',
152
- 'class' => 'SomeIvarJob',
153
- 'args' => '/tmp'
154
- )
155
-
156
- assert_equal(0, Resque::Scheduler.rufus_scheduler.jobs.size)
157
- assert_equal(0, Resque::Scheduler.scheduled_jobs.size)
158
- assert !Resque::Scheduler.scheduled_jobs.keys.include?('some_ivar_job')
159
- end
160
-
161
- test 'load_schedule_job with an empty cron' do
162
- Resque::Scheduler.load_schedule_job(
163
- 'some_ivar_job',
164
- 'cron' => '',
165
- 'class' => 'SomeIvarJob',
166
- 'args' => '/tmp'
167
- )
168
-
169
- assert_equal(0, Resque::Scheduler.rufus_scheduler.jobs.size)
170
- assert_equal(0, Resque::Scheduler.scheduled_jobs.size)
171
- assert !Resque::Scheduler.scheduled_jobs.keys.include?('some_ivar_job')
172
- end
173
-
174
- test 'update_schedule' do
175
- Resque::Scheduler.dynamic = true
176
- Resque.schedule = {
177
- 'some_ivar_job' => {
178
- 'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => '/tmp'
179
- },
180
- 'another_ivar_job' => {
181
- 'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => '/tmp/5'
182
- },
183
- 'stay_put_job' => {
184
- 'cron' => '* * * * *', 'class' => 'SomeJob', 'args' => '/tmp'
185
- }
186
- }
187
-
188
- Resque::Scheduler.load_schedule!
189
-
190
- Resque.set_schedule(
191
- 'some_ivar_job',
192
- 'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => '/tmp/2 '
193
- )
194
- Resque.set_schedule(
195
- 'new_ivar_job',
196
- 'cron' => '* * * * *', 'class' => 'SomeJob', 'args' => '/tmp/3 '
197
- )
198
- Resque.set_schedule(
199
- 'stay_put_job',
200
- 'cron' => '* * * * *', 'class' => 'SomeJob', 'args' => '/tmp '
201
- )
202
- Resque.remove_schedule('another_ivar_job')
203
-
204
- Resque::Scheduler.update_schedule
205
-
206
- assert_equal(3, Resque::Scheduler.rufus_scheduler.jobs.size)
207
- assert_equal(3, Resque::Scheduler.scheduled_jobs.size)
208
- %w(some_ivar_job new_ivar_job stay_put_job).each do |job_name|
209
- assert Resque::Scheduler.scheduled_jobs.keys.include?(job_name)
210
- assert Resque.schedule.keys.include?(job_name)
211
- end
212
- assert !Resque::Scheduler.scheduled_jobs.keys.include?('another_ivar_job')
213
- assert !Resque.schedule.keys.include?('another_ivar_job')
214
- assert_equal 0, Resque.redis.scard(:schedules_changed)
215
- end
216
-
217
- test 'update_schedule when all jobs have been removed' do
218
- Resque::Scheduler.dynamic = true
219
- Resque.schedule = {
220
- 'some_ivar_job' => {
221
- 'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => '/tmp'
222
- }
223
- }
224
-
225
- Resque::Scheduler.load_schedule!
226
-
227
- Resque.remove_schedule('some_ivar_job')
228
-
229
- Resque::Scheduler.update_schedule
230
-
231
- assert_equal(0, Resque::Scheduler.rufus_scheduler.jobs.size)
232
- assert_equal(0, Resque::Scheduler.scheduled_jobs.size)
233
- assert_equal([], Resque::Scheduler.scheduled_jobs.keys)
234
- assert_equal 0, Resque.redis.scard(:schedules_changed)
235
- end
236
-
237
- test 'update_schedule with mocks' do
238
- Resque::Scheduler.dynamic = true
239
- Resque.schedule = {
240
- 'some_ivar_job' => {
241
- 'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => '/tmp'
242
- },
243
- 'another_ivar_job' => {
244
- 'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => '/tmp/5'
245
- },
246
- 'stay_put_job' => {
247
- 'cron' => '* * * * *', 'class' => 'SomeJob', 'args' => '/tmp'
248
- }
249
- }
250
-
251
- Resque::Scheduler.load_schedule!
252
-
253
- Resque.set_schedule(
254
- 'some_ivar_job',
255
- 'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => '/tmp/2 '
256
- )
257
- Resque.set_schedule(
258
- 'new_ivar_job',
259
- 'cron' => '* * * * *', 'class' => 'SomeJob', 'args' => '/tmp/3 '
260
- )
261
- Resque.set_schedule(
262
- 'stay_put_job',
263
- 'cron' => '* * * * *', 'class' => 'SomeJob', 'args' => '/tmp '
264
- )
265
- Resque.remove_schedule('another_ivar_job')
266
-
267
- Resque::Scheduler.update_schedule
268
-
269
- assert_equal(3, Resque::Scheduler.scheduled_jobs.size)
270
- %w(some_ivar_job new_ivar_job stay_put_job).each do |job_name|
271
- assert Resque::Scheduler.scheduled_jobs.keys.include?(job_name)
272
- assert Resque.schedule.keys.include?(job_name)
273
- end
274
- assert !Resque::Scheduler.scheduled_jobs.keys.include?('another_ivar_job')
275
- assert !Resque.schedule.keys.include?('another_ivar_job')
276
- assert_equal 0, Resque.redis.scard(:schedules_changed)
277
- end
278
-
279
- test 'concurrent update_schedule calls' do
280
- Resque::Scheduler.dynamic = true
281
- Resque::Scheduler.load_schedule!
282
- jobs_count = 100
283
-
284
- background_delayed_update = Thread.new do
285
- sleep(0.01)
286
- Resque::Scheduler.update_schedule
287
- end
288
-
289
- (0...jobs_count).each do |i|
290
- Resque.set_schedule(
291
- "some_ivar_job#{i}",
292
- 'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => "/tmp/#{i}"
293
- )
294
- end
295
-
296
- background_delayed_update.join
297
- Resque::Scheduler.update_schedule
298
- assert_equal(jobs_count, Resque::Scheduler.rufus_scheduler.jobs.size)
299
- assert_equal(jobs_count, Resque::Scheduler.scheduled_jobs.size)
300
- assert_equal 0, Resque.redis.scard(:schedules_changed)
301
- end
302
-
303
- test 'schedule= sets the schedule' do
304
- Resque::Scheduler.dynamic = true
305
- Resque.schedule = {
306
- 'my_ivar_job' => {
307
- 'cron' => '* * * * *',
308
- 'class' => 'SomeIvarJob',
309
- 'args' => '/tmp/75'
310
- }
311
- }
312
- assert_equal(
313
- { 'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => '/tmp/75' },
314
- Resque.schedule['my_ivar_job']
315
- )
316
- end
317
-
318
- test 'schedule= removes schedules not present in the given ' \
319
- 'schedule argument' do
320
- Resque::Scheduler.dynamic = true
321
-
322
- Resque.schedule = {
323
- 'old_job' => { 'cron' => '* * * * *', 'class' => 'OldJob' }
324
- }
325
- assert_equal(
326
- { 'old_job' => { 'cron' => '* * * * *', 'class' => 'OldJob' } },
327
- Resque.schedule
328
- )
329
-
330
- Resque.schedule = {
331
- 'new_job' => { 'cron' => '* * * * *', 'class' => 'NewJob' }
332
- }
333
- Resque.reload_schedule!
334
- assert_equal(
335
- { 'new_job' => { 'cron' => '* * * * *', 'class' => 'NewJob' } },
336
- Resque.schedule
337
- )
338
- end
339
-
340
- test "schedule= uses job name as 'class' argument if it's missing" do
341
- Resque::Scheduler.dynamic = true
342
- Resque.schedule = { 'SomeIvarJob' => {
343
- 'cron' => '* * * * *', 'args' => '/tmp/75'
344
- } }
345
- assert_equal(
346
- { 'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => '/tmp/75' },
347
- Resque.schedule['SomeIvarJob']
348
- )
349
- assert_equal('SomeIvarJob', Resque.schedule['SomeIvarJob']['class'])
350
- end
351
-
352
- test 'schedule= does not mutate argument' do
353
- schedule = { 'SomeIvarJob' => {
354
- 'cron' => '* * * * *', 'args' => '/tmp/75'
355
- } }
356
- Resque.schedule = schedule
357
- assert !schedule['SomeIvarJob'].key?('class')
358
- end
359
-
360
- test 'set_schedule can set an individual schedule' do
361
- Resque.set_schedule(
362
- 'some_ivar_job',
363
- 'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => '/tmp/22'
364
- )
365
- assert_equal(
366
- { 'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => '/tmp/22' },
367
- Resque.schedule['some_ivar_job']
368
- )
369
- assert Resque.redis.sismember(:schedules_changed, 'some_ivar_job')
370
- end
371
-
372
- test 'fetch_schedule returns a schedule' do
373
- Resque.schedule = {
374
- 'some_ivar_job2' => {
375
- 'cron' => '* * * * *',
376
- 'class' => 'SomeIvarJob',
377
- 'args' => '/tmp/33'
378
- }
379
- }
380
- assert_equal(
381
- { 'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => '/tmp/33' },
382
- Resque.fetch_schedule('some_ivar_job2')
383
- )
384
- end
385
-
386
- test 'remove_schedule removes a schedule' do
387
- Resque.set_schedule(
388
- 'some_ivar_job3',
389
- 'cron' => '* * * * *',
390
- 'class' => 'SomeIvarJob',
391
- 'args' => '/tmp/44',
392
- 'persist' => true
393
- )
394
- Resque::Scheduler.load_schedule!
395
- Resque.remove_schedule('some_ivar_job3')
396
- assert_equal nil, Resque.redis.hget(:schedules, 'some_ivar_job3')
397
- assert Resque.redis.sismember(:schedules_changed, 'some_ivar_job3')
398
- assert_equal [], Resque.redis.smembers(:persisted_schedules)
399
- end
400
-
401
- test 'persisted schedules' do
402
- Resque.set_schedule(
403
- 'some_ivar_job',
404
- 'cron' => '* * * * *',
405
- 'class' => 'SomeIvarJob',
406
- 'args' => '/tmp/2',
407
- 'persist' => true
408
- )
409
- Resque.set_schedule(
410
- 'new_ivar_job',
411
- 'cron' => '* * * * *',
412
- 'class' => 'SomeJob',
413
- 'args' => '/tmp/3 '
414
- )
415
-
416
- Resque.schedule = {
417
- 'a_schedule' => {
418
- 'cron' => '* * * * *', 'class' => 'SomeOtherJob', 'args' => '/tmp'
419
- }
420
- }
421
- Resque::Scheduler.load_schedule!
422
-
423
- assert_equal(
424
- { 'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => '/tmp/2' },
425
- Resque.schedule['some_ivar_job']
426
- )
427
- assert_equal(nil, Resque.schedule['some_job'])
428
- end
429
-
430
- test 'adheres to lint' do
431
- assert_nothing_raised do
432
- Resque::Plugin.lint(Resque::Scheduler)
433
- Resque::Plugin.lint(Resque::Scheduler::Extension)
434
- end
435
- end
436
-
437
- test 'procline contains app_name when present' do
438
- Resque::Scheduler.app_name = 'foo'
439
- assert Resque::Scheduler.send(:build_procline, 'bar') =~ /\[foo\]:/
440
- end
441
-
442
- test 'procline omits app_name when absent' do
443
- Resque::Scheduler.app_name = nil
444
- assert Resque::Scheduler.send(:build_procline, 'bar') =~
445
- /#{Resque::Scheduler.send(:internal_name)}: bar/
446
- end
447
-
448
- test 'procline contains env when present' do
449
- Resque::Scheduler.env = 'xyz'
450
- assert Resque::Scheduler.send(:build_procline, 'cage') =~ /\[xyz\]: cage/
451
- end
452
-
453
- test 'procline omits env when absent' do
454
- Resque::Scheduler.env = nil
455
- assert Resque::Scheduler.send(:build_procline, 'cage') =~
456
- /#{Resque::Scheduler.send(:internal_name)}: cage/
457
- end
458
-
459
- context 'printing schedule' do
460
- setup do
461
- Resque::Scheduler.expects(:log!).at_least_once
462
- end
463
-
464
- test 'prints schedule' do
465
- fake_rufus_scheduler = mock
466
- fake_rufus_scheduler.expects(:jobs).at_least_once
467
- .returns(foo: OpenStruct.new(t: nil, last: nil))
468
- Resque::Scheduler.expects(:rufus_scheduler).at_least_once
469
- .returns(fake_rufus_scheduler)
470
- Resque::Scheduler.print_schedule
471
- end
472
- end
473
- end