resque 1.23.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/HISTORY.md +271 -0
  3. data/README.markdown +454 -484
  4. data/Rakefile +4 -17
  5. data/bin/resque-web +10 -22
  6. data/lib/resque/data_store.rb +335 -0
  7. data/lib/resque/errors.rb +15 -1
  8. data/lib/resque/failure/airbrake.rb +32 -4
  9. data/lib/resque/failure/base.rb +16 -7
  10. data/lib/resque/failure/multiple.rb +26 -8
  11. data/lib/resque/failure/redis.rb +92 -15
  12. data/lib/resque/failure/redis_multi_queue.rb +104 -0
  13. data/lib/resque/failure.rb +62 -32
  14. data/lib/resque/helpers.rb +11 -57
  15. data/lib/resque/job.rb +79 -12
  16. data/lib/resque/log_formatters/quiet_formatter.rb +7 -0
  17. data/lib/resque/log_formatters/verbose_formatter.rb +7 -0
  18. data/lib/resque/log_formatters/very_verbose_formatter.rb +8 -0
  19. data/lib/resque/logging.rb +18 -0
  20. data/lib/resque/plugin.rb +22 -10
  21. data/lib/resque/railtie.rb +10 -0
  22. data/lib/resque/server/public/jquery-3.6.0.min.js +2 -0
  23. data/lib/resque/server/public/jquery.relatize_date.js +4 -4
  24. data/lib/resque/server/public/main.js +3 -0
  25. data/lib/resque/server/public/ranger.js +16 -8
  26. data/lib/resque/server/public/style.css +13 -8
  27. data/lib/resque/server/views/error.erb +1 -1
  28. data/lib/resque/server/views/failed.erb +27 -59
  29. data/lib/resque/server/views/failed_job.erb +50 -0
  30. data/lib/resque/server/views/failed_queues_overview.erb +24 -0
  31. data/lib/resque/server/views/job_class.erb +8 -0
  32. data/lib/resque/server/views/key_sets.erb +2 -4
  33. data/lib/resque/server/views/key_string.erb +1 -1
  34. data/lib/resque/server/views/layout.erb +7 -6
  35. data/lib/resque/server/views/next_more.erb +22 -10
  36. data/lib/resque/server/views/processing.erb +2 -0
  37. data/lib/resque/server/views/queues.erb +22 -13
  38. data/lib/resque/server/views/stats.erb +5 -5
  39. data/lib/resque/server/views/workers.erb +4 -4
  40. data/lib/resque/server/views/working.erb +10 -11
  41. data/lib/resque/server.rb +51 -108
  42. data/lib/resque/server_helper.rb +185 -0
  43. data/lib/resque/stat.rb +19 -7
  44. data/lib/resque/tasks.rb +26 -25
  45. data/lib/resque/thread_signal.rb +24 -0
  46. data/lib/resque/vendor/utf8_util.rb +2 -8
  47. data/lib/resque/version.rb +1 -1
  48. data/lib/resque/web_runner.rb +374 -0
  49. data/lib/resque/worker.rb +487 -163
  50. data/lib/resque.rb +332 -52
  51. data/lib/tasks/redis.rake +11 -11
  52. metadata +169 -149
  53. data/lib/resque/failure/hoptoad.rb +0 -33
  54. data/lib/resque/failure/thoughtbot.rb +0 -33
  55. data/lib/resque/server/public/jquery-1.3.2.min.js +0 -19
  56. data/lib/resque/server/test_helper.rb +0 -19
  57. data/lib/resque/vendor/utf8_util/utf8_util_18.rb +0 -91
  58. data/lib/resque/vendor/utf8_util/utf8_util_19.rb +0 -5
  59. data/test/airbrake_test.rb +0 -27
  60. data/test/hoptoad_test.rb +0 -26
  61. data/test/job_hooks_test.rb +0 -464
  62. data/test/job_plugins_test.rb +0 -230
  63. data/test/plugin_test.rb +0 -116
  64. data/test/redis-test-cluster.conf +0 -115
  65. data/test/redis-test.conf +0 -115
  66. data/test/resque-web_test.rb +0 -59
  67. data/test/resque_failure_redis_test.rb +0 -19
  68. data/test/resque_test.rb +0 -278
  69. data/test/test_helper.rb +0 -178
  70. data/test/worker_test.rb +0 -657
@@ -1,91 +0,0 @@
1
- require 'strscan'
2
-
3
- module UTF8Util
4
- HIGH_BIT_RANGE = /[\x80-\xff]/
5
-
6
- # Check if this String is valid UTF-8
7
- #
8
- # Returns true or false.
9
- def self.valid?(str)
10
- sc = StringScanner.new(str)
11
-
12
- while sc.skip_until(HIGH_BIT_RANGE)
13
- sc.pos -= 1
14
-
15
- if !sequence_length(sc)
16
- return false
17
- end
18
- end
19
-
20
- true
21
- end
22
-
23
- # Replace invalid UTF-8 character sequences with a replacement character
24
- #
25
- # Returns self as valid UTF-8.
26
- def self.clean!(str)
27
- sc = StringScanner.new(str)
28
- while sc.skip_until(HIGH_BIT_RANGE)
29
- pos = sc.pos = sc.pos-1
30
-
31
- if !sequence_length(sc)
32
- str[pos] = REPLACEMENT_CHAR
33
- end
34
- end
35
-
36
- str
37
- end
38
-
39
- # Validate the UTF-8 sequence at the current scanner position.
40
- #
41
- # scanner - StringScanner instance so we can advance the pointer as we verify.
42
- #
43
- # Returns The length in bytes of this UTF-8 sequence, false if invalid.
44
- def self.sequence_length(scanner)
45
- leader = scanner.get_byte[0]
46
-
47
- if (leader >> 5) == 0x6
48
- if check_next_sequence(scanner)
49
- return 2
50
- else
51
- scanner.pos -= 1
52
- end
53
- elsif (leader >> 4) == 0x0e
54
- if check_next_sequence(scanner)
55
- if check_next_sequence(scanner)
56
- return 3
57
- else
58
- scanner.pos -= 2
59
- end
60
- else
61
- scanner.pos -= 1
62
- end
63
- elsif (leader >> 3) == 0x1e
64
- if check_next_sequence(scanner)
65
- if check_next_sequence(scanner)
66
- if check_next_sequence(scanner)
67
- return 4
68
- else
69
- scanner.pos -= 3
70
- end
71
- else
72
- scanner.pos -= 2
73
- end
74
- else
75
- scanner.pos -= 1
76
- end
77
- end
78
-
79
- false
80
- end
81
-
82
- private
83
-
84
- # Read another byte off the scanner oving the scan position forward one place
85
- #
86
- # Returns nothing.
87
- def self.check_next_sequence(scanner)
88
- byte = scanner.get_byte[0]
89
- (byte >> 6) == 0x2
90
- end
91
- end
@@ -1,5 +0,0 @@
1
- module UTF8Util
2
- def self.clean!(str)
3
- str.force_encoding("binary").encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => REPLACEMENT_CHAR)
4
- end
5
- end
@@ -1,27 +0,0 @@
1
-
2
- require 'test_helper'
3
-
4
- begin
5
- require 'airbrake'
6
- rescue LoadError
7
- warn "Install airbrake gem to run Airbrake tests."
8
- end
9
-
10
- if defined? Airbrake
11
- require 'resque/failure/airbrake'
12
- context "Airbrake" do
13
- test "should be notified of an error" do
14
- exception = StandardError.new("BOOM")
15
- worker = Resque::Worker.new(:test)
16
- queue = "test"
17
- payload = {'class' => Object, 'args' => 66}
18
-
19
- Airbrake.expects(:notify_or_ignore).with(
20
- exception,
21
- :parameters => {:payload_class => 'Object', :payload_args => '66'})
22
-
23
- backend = Resque::Failure::Airbrake.new(exception, worker, queue, payload)
24
- backend.save
25
- end
26
- end
27
- end
data/test/hoptoad_test.rb DELETED
@@ -1,26 +0,0 @@
1
- require 'test_helper'
2
-
3
- begin
4
- require 'hoptoad_notifier'
5
- rescue LoadError
6
- warn "Install hoptoad_notifier gem to run Hoptoad tests."
7
- end
8
-
9
- if defined? HoptoadNotifier
10
- require 'resque/failure/hoptoad'
11
- context "Hoptoad" do
12
- test "should be notified of an error" do
13
- exception = StandardError.new("BOOM")
14
- worker = Resque::Worker.new(:test)
15
- queue = "test"
16
- payload = {'class' => Object, 'args' => 66}
17
-
18
- HoptoadNotifier.expects(:notify_or_ignore).with(
19
- exception,
20
- :parameters => {:payload_class => 'Object', :payload_args => '66'})
21
-
22
- backend = Resque::Failure::Hoptoad.new(exception, worker, queue, payload)
23
- backend.save
24
- end
25
- end
26
- end
@@ -1,464 +0,0 @@
1
- require 'test_helper'
2
-
3
- context "Resque::Job before_perform" do
4
- include PerformJob
5
-
6
- class ::BeforePerformJob
7
- def self.before_perform_record_history(history)
8
- history << :before_perform
9
- end
10
-
11
- def self.perform(history)
12
- history << :perform
13
- end
14
- end
15
-
16
- test "it runs before_perform before perform" do
17
- result = perform_job(BeforePerformJob, history=[])
18
- assert_equal true, result, "perform returned true"
19
- assert_equal history, [:before_perform, :perform]
20
- end
21
-
22
- class ::BeforePerformJobFails
23
- def self.before_perform_fail_job(history)
24
- history << :before_perform
25
- raise StandardError
26
- end
27
- def self.perform(history)
28
- history << :perform
29
- end
30
- end
31
-
32
- test "raises an error and does not perform if before_perform fails" do
33
- history = []
34
- assert_raises StandardError do
35
- perform_job(BeforePerformJobFails, history)
36
- end
37
- assert_equal history, [:before_perform], "Only before_perform was run"
38
- end
39
-
40
- class ::BeforePerformJobAborts
41
- def self.before_perform_abort(history)
42
- history << :before_perform
43
- raise Resque::Job::DontPerform
44
- end
45
- def self.perform(history)
46
- history << :perform
47
- end
48
- end
49
-
50
- test "does not perform if before_perform raises Resque::Job::DontPerform" do
51
- result = perform_job(BeforePerformJobAborts, history=[])
52
- assert_equal false, result, "perform returned false"
53
- assert_equal history, [:before_perform], "Only before_perform was run"
54
- end
55
- end
56
-
57
- context "Resque::Job after_perform" do
58
- include PerformJob
59
-
60
- class ::AfterPerformJob
61
- def self.perform(history)
62
- history << :perform
63
- end
64
- def self.after_perform_record_history(history)
65
- history << :after_perform
66
- end
67
- end
68
-
69
- test "it runs after_perform after perform" do
70
- result = perform_job(AfterPerformJob, history=[])
71
- assert_equal true, result, "perform returned true"
72
- assert_equal history, [:perform, :after_perform]
73
- end
74
-
75
- class ::AfterPerformJobFails
76
- def self.perform(history)
77
- history << :perform
78
- end
79
- def self.after_perform_fail_job(history)
80
- history << :after_perform
81
- raise StandardError
82
- end
83
- end
84
-
85
- test "raises an error but has already performed if after_perform fails" do
86
- history = []
87
- assert_raises StandardError do
88
- perform_job(AfterPerformJobFails, history)
89
- end
90
- assert_equal history, [:perform, :after_perform], "Only after_perform was run"
91
- end
92
- end
93
-
94
- context "Resque::Job around_perform" do
95
- include PerformJob
96
-
97
- class ::AroundPerformJob
98
- def self.perform(history)
99
- history << :perform
100
- end
101
- def self.around_perform_record_history(history)
102
- history << :start_around_perform
103
- yield
104
- history << :finish_around_perform
105
- end
106
- end
107
-
108
- test "it runs around_perform then yields in order to perform" do
109
- result = perform_job(AroundPerformJob, history=[])
110
- assert_equal true, result, "perform returned true"
111
- assert_equal history, [:start_around_perform, :perform, :finish_around_perform]
112
- end
113
-
114
- class ::AroundPerformJobFailsBeforePerforming
115
- def self.perform(history)
116
- history << :perform
117
- end
118
- def self.around_perform_fail(history)
119
- history << :start_around_perform
120
- raise StandardError
121
- yield
122
- history << :finish_around_perform
123
- end
124
- end
125
-
126
- test "raises an error and does not perform if around_perform fails before yielding" do
127
- history = []
128
- assert_raises StandardError do
129
- perform_job(AroundPerformJobFailsBeforePerforming, history)
130
- end
131
- assert_equal history, [:start_around_perform], "Only part of around_perform was run"
132
- end
133
-
134
- class ::AroundPerformJobFailsWhilePerforming
135
- def self.perform(history)
136
- history << :perform
137
- raise StandardError
138
- end
139
- def self.around_perform_fail_in_yield(history)
140
- history << :start_around_perform
141
- begin
142
- yield
143
- ensure
144
- history << :ensure_around_perform
145
- end
146
- history << :finish_around_perform
147
- end
148
- end
149
-
150
- test "raises an error but may handle exceptions if perform fails" do
151
- history = []
152
- assert_raises StandardError do
153
- perform_job(AroundPerformJobFailsWhilePerforming, history)
154
- end
155
- assert_equal history, [:start_around_perform, :perform, :ensure_around_perform], "Only part of around_perform was run"
156
- end
157
-
158
- class ::AroundPerformJobDoesNotHaveToYield
159
- def self.perform(history)
160
- history << :perform
161
- end
162
- def self.around_perform_dont_yield(history)
163
- history << :start_around_perform
164
- history << :finish_around_perform
165
- end
166
- end
167
-
168
- test "around_perform is not required to yield" do
169
- history = []
170
- result = perform_job(AroundPerformJobDoesNotHaveToYield, history)
171
- assert_equal false, result, "perform returns false"
172
- assert_equal history, [:start_around_perform, :finish_around_perform], "perform was not run"
173
- end
174
- end
175
-
176
- context "Resque::Job on_failure" do
177
- include PerformJob
178
-
179
- class ::FailureJobThatDoesNotFail
180
- def self.perform(history)
181
- history << :perform
182
- end
183
- def self.on_failure_record_failure(exception, history)
184
- history << exception.message
185
- end
186
- end
187
-
188
- test "it does not call on_failure if no failures occur" do
189
- result = perform_job(FailureJobThatDoesNotFail, history=[])
190
- assert_equal true, result, "perform returned true"
191
- assert_equal history, [:perform]
192
- end
193
-
194
- class ::FailureJobThatFails
195
- def self.perform(history)
196
- history << :perform
197
- raise StandardError, "oh no"
198
- end
199
- def self.on_failure_record_failure(exception, history)
200
- history << exception.message
201
- end
202
- end
203
-
204
- test "it calls on_failure with the exception and then re-raises the exception" do
205
- history = []
206
- assert_raises StandardError do
207
- perform_job(FailureJobThatFails, history)
208
- end
209
- assert_equal history, [:perform, "oh no"]
210
- end
211
-
212
- class ::FailureJobThatFailsBadly
213
- def self.perform(history)
214
- history << :perform
215
- raise SyntaxError, "oh no"
216
- end
217
- def self.on_failure_record_failure(exception, history)
218
- history << exception.message
219
- end
220
- end
221
-
222
- test "it calls on_failure even with bad exceptions" do
223
- history = []
224
- assert_raises SyntaxError do
225
- perform_job(FailureJobThatFailsBadly, history)
226
- end
227
- assert_equal history, [:perform, "oh no"]
228
- end
229
- end
230
-
231
- context "Resque::Job after_enqueue" do
232
- include PerformJob
233
-
234
- class ::AfterEnqueueJob
235
- @queue = :jobs
236
- def self.after_enqueue_record_history(history)
237
- history << :after_enqueue
238
- end
239
-
240
- def self.perform(history)
241
- end
242
- end
243
-
244
- test "the after enqueue hook should run" do
245
- history = []
246
- @worker = Resque::Worker.new(:jobs)
247
- Resque.enqueue(AfterEnqueueJob, history)
248
- @worker.work(0)
249
- assert_equal history, [:after_enqueue], "after_enqueue was not run"
250
- end
251
- end
252
-
253
-
254
- context "Resque::Job before_enqueue" do
255
- include PerformJob
256
-
257
- class ::BeforeEnqueueJob
258
- @queue = :jobs
259
- def self.before_enqueue_record_history(history)
260
- history << :before_enqueue
261
- end
262
-
263
- def self.perform(history)
264
- end
265
- end
266
-
267
- class ::BeforeEnqueueJobAbort
268
- @queue = :jobs
269
- def self.before_enqueue_abort(history)
270
- false
271
- end
272
-
273
- def self.perform(history)
274
- end
275
- end
276
-
277
- test "the before enqueue hook should run" do
278
- history = []
279
- @worker = Resque::Worker.new(:jobs)
280
- assert Resque.enqueue(BeforeEnqueueJob, history)
281
- @worker.work(0)
282
- assert_equal history, [:before_enqueue], "before_enqueue was not run"
283
- end
284
-
285
- test "a before enqueue hook that returns false should prevent the job from getting queued" do
286
- history = []
287
- @worker = Resque::Worker.new(:jobs)
288
- assert_nil Resque.enqueue(BeforeEnqueueJobAbort, history)
289
- assert_equal 0, Resque.size(:jobs)
290
- end
291
- end
292
-
293
- context "Resque::Job after_dequeue" do
294
- include PerformJob
295
-
296
- class ::AfterDequeueJob
297
- @queue = :jobs
298
- def self.after_dequeue_record_history(history)
299
- history << :after_dequeue
300
- end
301
-
302
- def self.perform(history)
303
- end
304
- end
305
-
306
- test "the after dequeue hook should run" do
307
- history = []
308
- @worker = Resque::Worker.new(:jobs)
309
- Resque.dequeue(AfterDequeueJob, history)
310
- @worker.work(0)
311
- assert_equal history, [:after_dequeue], "after_dequeue was not run"
312
- end
313
- end
314
-
315
-
316
- context "Resque::Job before_dequeue" do
317
- include PerformJob
318
-
319
- class ::BeforeDequeueJob
320
- @queue = :jobs
321
- def self.before_dequeue_record_history(history)
322
- history << :before_dequeue
323
- end
324
-
325
- def self.perform(history)
326
- end
327
- end
328
-
329
- class ::BeforeDequeueJobAbort
330
- @queue = :jobs
331
- def self.before_dequeue_abort(history)
332
- false
333
- end
334
-
335
- def self.perform(history)
336
- end
337
- end
338
-
339
- test "the before dequeue hook should run" do
340
- history = []
341
- @worker = Resque::Worker.new(:jobs)
342
- Resque.dequeue(BeforeDequeueJob, history)
343
- @worker.work(0)
344
- assert_equal history, [:before_dequeue], "before_dequeue was not run"
345
- end
346
-
347
- test "a before dequeue hook that returns false should prevent the job from getting dequeued" do
348
- history = []
349
- assert_equal nil, Resque.dequeue(BeforeDequeueJobAbort, history)
350
- end
351
- end
352
-
353
- context "Resque::Job all hooks" do
354
- include PerformJob
355
-
356
- class ::VeryHookyJob
357
- def self.before_perform_record_history(history)
358
- history << :before_perform
359
- end
360
- def self.around_perform_record_history(history)
361
- history << :start_around_perform
362
- yield
363
- history << :finish_around_perform
364
- end
365
- def self.perform(history)
366
- history << :perform
367
- end
368
- def self.after_perform_record_history(history)
369
- history << :after_perform
370
- end
371
- def self.on_failure_record_history(exception, history)
372
- history << exception.message
373
- end
374
- end
375
-
376
- test "the complete hook order" do
377
- result = perform_job(VeryHookyJob, history=[])
378
- assert_equal true, result, "perform returned true"
379
- assert_equal history, [
380
- :before_perform,
381
- :start_around_perform,
382
- :perform,
383
- :finish_around_perform,
384
- :after_perform
385
- ]
386
- end
387
-
388
- class ::VeryHookyJobThatFails
389
- def self.before_perform_record_history(history)
390
- history << :before_perform
391
- end
392
- def self.around_perform_record_history(history)
393
- history << :start_around_perform
394
- yield
395
- history << :finish_around_perform
396
- end
397
- def self.perform(history)
398
- history << :perform
399
- end
400
- def self.after_perform_record_history(history)
401
- history << :after_perform
402
- raise StandardError, "oh no"
403
- end
404
- def self.on_failure_record_history(exception, history)
405
- history << exception.message
406
- end
407
- end
408
-
409
- test "the complete hook order with a failure at the last minute" do
410
- history = []
411
- assert_raises StandardError do
412
- perform_job(VeryHookyJobThatFails, history)
413
- end
414
- assert_equal history, [
415
- :before_perform,
416
- :start_around_perform,
417
- :perform,
418
- :finish_around_perform,
419
- :after_perform,
420
- "oh no"
421
- ]
422
- end
423
-
424
- class ::CallbacksInline
425
- @queue = :callbacks_inline
426
-
427
- def self.before_perform_record_history(history, count)
428
- history << :before_perform
429
- count['count'] += 1
430
- end
431
-
432
- def self.after_perform_record_history(history, count)
433
- history << :after_perform
434
- count['count'] += 1
435
- end
436
-
437
- def self.around_perform_record_history(history, count)
438
- history << :start_around_perform
439
- count['count'] += 1
440
- yield
441
- history << :finish_around_perform
442
- count['count'] += 1
443
- end
444
-
445
- def self.perform(history, count)
446
- history << :perform
447
- $history = history
448
- $count = count
449
- end
450
- end
451
-
452
- test "it runs callbacks when inline is true" do
453
- begin
454
- Resque.inline = true
455
- # Sending down two parameters that can be passed and updated by reference
456
- result = Resque.enqueue(CallbacksInline, [], {'count' => 0})
457
- assert_equal true, result, "perform returned true"
458
- assert_equal $history, [:before_perform, :start_around_perform, :perform, :finish_around_perform, :after_perform]
459
- assert_equal 4, $count['count']
460
- ensure
461
- Resque.inline = false
462
- end
463
- end
464
- end