ae_active_job_state 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ae_active_job_state/has_job_state.rb +19 -3
- data/lib/ae_active_job_state/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1747e2cb848f546f8b4210b75b3540fb60413a81fa2510dacf2d48acb010b86
|
4
|
+
data.tar.gz: 7c0d074c03fc054d05b065192851c9de78d1b69e1a614b5e05671a589cc2a3fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b5edff3c15d307f646181ceeec2efc4b4ad4e025d65dc030bacf4930f2ccd0a6d3dcebb925524593ed58729c8bf4e32e077fcc915295538f8be6bc34119d50c
|
7
|
+
data.tar.gz: 84ba277e93492eff5ba4c9fb3aeac0cb717cfe98a9d70970a11c9341d0c5ac00c6513eb90684452bf15a8da425e038c2c82d5bcab04bacdd4d48e86c344aca16
|
@@ -17,9 +17,25 @@ module AeActiveJobState
|
|
17
17
|
end
|
18
18
|
|
19
19
|
around_perform do |job, block|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
# This is effectively the same logic as #create_or_find_by!, the main difference is we also fail on
|
21
|
+
# RecordInvalid. This allows us to have additional uniqueness validations in the model and still fall back to
|
22
|
+
# the find_by.
|
23
|
+
#
|
24
|
+
# We do this here to prevent a race condition if the job is processed before the initial job state is created.
|
25
|
+
# This can occur in the case that the job is enqueued in a transaction and a worker picks up the work before the
|
26
|
+
# transaction commits. In this case, this create will now wait on the insertion intention lock on the
|
27
|
+
# active_job_id index created by the insert in before_enqueue, throw a record not unique, then find the correct
|
28
|
+
# state model.
|
29
|
+
#
|
30
|
+
# We continue to handle the case where the state was fully inserted before this callback is hit and the case
|
31
|
+
# where the job was never enqueued.
|
32
|
+
begin
|
33
|
+
@job_state = AeActiveJobState::JobState.create!(status: 'pending', active_job_id: job.job_id,
|
34
|
+
args: job.arguments)
|
35
|
+
rescue ActiveRecord::RecordNotUnique, ActiveRecord::RecordInvalid
|
36
|
+
@job_state = AeActiveJobState::JobState.find_by!(active_job_id: job.job_id)
|
37
|
+
end
|
38
|
+
|
23
39
|
job_state.run!
|
24
40
|
job_state.reload
|
25
41
|
block.call
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ae_active_job_state
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AppFolio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aasm
|