File tree Expand file tree Collapse file tree 9 files changed +11
-85
lines changed Expand file tree Collapse file tree 9 files changed +11
-85
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
3
+ ## 0.14.0
4
+ - Reverts changes made in version 0.13.
5
+
3
6
## 0.13.0
4
7
- Moves ` on_cancellation ` logic from the before delayed job lifecycle hook to the after hook.
5
8
- Gem will now fail to load if ` Delayed::Worker.destroy_failed_jobs ` is set to true.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -62,18 +62,8 @@ def unblock
62
62
end
63
63
64
64
def cancel
65
- with_lock do
66
- return if destroyed?
67
-
68
- Delayed ::Job . enqueue ( on_cancellation_job , on_cancellation_job_options || { } ) if on_cancellation_job
69
- destroy
70
- end
71
- rescue ActiveRecord ::RecordNotFound
72
- # The first failing job to attempt cancelling the job group will enqueue the
73
- # on cancellation job and destroy the group. Any other concurrently failing job
74
- # in the same group can therefore silently return if the job group has already
75
- # been destroyed.
76
- nil
65
+ Delayed ::Job . enqueue ( on_cancellation_job , on_cancellation_job_options || { } ) if on_cancellation_job
66
+ destroy
77
67
end
78
68
79
69
def check_for_completion ( skip_pending_jobs_check : false )
Original file line number Diff line number Diff line change @@ -17,13 +17,7 @@ def job.max_attempts
17
17
end
18
18
end
19
19
20
- # In order to allow individual jobs in the JobGroup to perform cleanup activities upon
21
- # job failure, a JobGroups on cancellation job must be enqueued in the after failure
22
- # delayed job lifecycle hook. If both were to be performed in the same hook, the job's
23
- # failure hook and the on cancellation job may run at the same time since hook execution
24
- # order is never guaranteed. This is particular important if the on cancellation job
25
- # depends on state set in the failure hook of an individual job.
26
- lifecycle . after ( :failure ) do |_worker , job |
20
+ lifecycle . before ( :failure ) do |_worker , job |
27
21
# If a job in the job group fails, then cancel the whole job group.
28
22
# Need to check that the job group is present since another
29
23
# job may have concurrently cancelled it.
Original file line number Diff line number Diff line change @@ -4,15 +4,6 @@ module Delayed
4
4
module JobGroups
5
5
class Railtie < ::Rails ::Railtie
6
6
config . after_initialize do
7
-
8
- # On cancellation checks are performed in the after failure delayed job lifecycle, however
9
- # https://github.com/collectiveidea/delayed_job/blob/master/lib/delayed/worker.rb#L268 may
10
- # delete jobs before the hook runs. This could cause a successful job in the same group to
11
- # complete the group instead of the group being cancelled. Therefore, we must ensure that
12
- # the Delayed::Worker.destroy_failed_jobs is set to false, guaranteeing that the group is
13
- # never empty if failure occurs.
14
- raise Delayed ::JobGroups ::IncompatibleWithDelayedJobError if Delayed ::Worker . destroy_failed_jobs
15
-
16
7
Delayed ::Backend ::ActiveRecord ::Job . include ( Delayed ::JobGroups ::JobExtensions )
17
8
end
18
9
end
Original file line number Diff line number Diff line change 2
2
3
3
module Delayed
4
4
module JobGroups
5
- VERSION = '0.13 .0'
5
+ VERSION = '0.14 .0'
6
6
end
7
7
end
Original file line number Diff line number Diff line change 4
4
require 'active_record'
5
5
require 'delayed_job'
6
6
require 'delayed_job_active_record'
7
- require 'delayed/job_groups/errors'
8
7
require 'delayed/job_groups/compatibility'
9
8
require 'delayed/job_groups/complete_stuck_job_groups_job'
10
9
require 'delayed/job_groups/job_extensions'
19
18
else
20
19
# Do the same as in the railtie
21
20
Delayed ::Backend ::ActiveRecord ::Job . include ( Delayed ::JobGroups ::JobExtensions )
22
- raise Delayed ::JobGroups ::IncompatibleWithDelayedJobError if Delayed ::Worker . destroy_failed_jobs
23
21
end
24
22
25
23
Delayed ::Worker . plugins << Delayed ::JobGroups ::Plugin
Original file line number Diff line number Diff line change 299
299
end
300
300
301
301
describe "#cancel" do
302
- subject ( :job_group ) do
303
- create (
304
- :job_group ,
305
- on_completion_job : on_completion_job ,
306
- on_completion_job_options : on_completion_job_options ,
307
- on_cancellation_job : on_cancellation_job ,
308
- on_cancellation_job_options : on_cancellation_job_options ,
309
- blocked : blocked
310
- )
311
- end
312
-
313
302
let! ( :queued_job ) { Delayed ::Job . create! ( job_group_id : job_group . id ) }
314
303
let! ( :running_job ) { Delayed ::Job . create! ( job_group_id : job_group . id , locked_at : Time . now , locked_by : 'test' ) }
315
- let ( :before_hook ) { }
316
- let ( :on_cancellation_job ) { 'dummy job' }
317
- let ( :on_cancellation_job_options ) do
318
- { foo : 'bar' }
319
- end
320
- let ( :cancel ) { true }
321
304
322
305
before do
323
- job_group . cancel if cancel
306
+ job_group . cancel
324
307
end
325
308
326
309
it "destroys the job group" do
334
317
it "does not destroy running jobs" do
335
318
expect ( running_job ) . not_to have_been_destroyed
336
319
end
337
-
338
- context "when already cancelled" do
339
- let ( :cancel ) { false }
340
-
341
- it "skips cancel block if already cancelled" do
342
- other = Delayed ::JobGroups ::JobGroup . find ( job_group . id )
343
- job_group . cancel
344
-
345
- other . cancel
346
- other . cancel
347
-
348
- expect ( Delayed ::Job )
349
- . to have_received ( :enqueue ) . with ( on_cancellation_job , on_cancellation_job_options ) . once
350
- end
351
- end
352
320
end
353
321
354
322
describe "#failure_cancels_group?" do
Original file line number Diff line number Diff line change 13
13
14
14
require 'rspec/its'
15
15
require 'database_cleaner'
16
- require 'delayed_job'
17
-
18
- Delayed ::Worker . read_ahead = 1
19
- Delayed ::Worker . destroy_failed_jobs = false
20
-
21
16
require 'delayed_job_groups_plugin'
22
17
require 'factory_bot'
23
18
require 'yaml'
28
23
29
24
FileUtils . makedirs ( 'log' )
30
25
26
+ Delayed ::Worker . read_ahead = 1
27
+ Delayed ::Worker . destroy_failed_jobs = false
28
+
31
29
Delayed ::Worker . logger = Logger . new ( 'log/test.log' )
32
30
Delayed ::Worker . logger . level = Logger ::DEBUG
33
31
ActiveRecord ::Base . logger = Delayed ::Worker . logger
You can’t perform that action at this time.
0 commit comments