ae_active_job_state 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8fbbc040ea54164e68433c3d291e388386bf6e6b6ef770afda14cb58191d9b2f
4
- data.tar.gz: e714144e28307b336696804b07d8af1aa57efea378aaf6631c31b3836186ab25
3
+ metadata.gz: e1747e2cb848f546f8b4210b75b3540fb60413a81fa2510dacf2d48acb010b86
4
+ data.tar.gz: 7c0d074c03fc054d05b065192851c9de78d1b69e1a614b5e05671a589cc2a3fb
5
5
  SHA512:
6
- metadata.gz: cda4cf5a133194f6f91810677e3e26d9abe3e4cb6174840c8a9b873e56f0d1a2ee316f48520f0703dd5a6be416a4aefc09e5dd95f0d72419df1cb63a2ecf0f1a
7
- data.tar.gz: 2e86b1f8efb7a387d2a74236df9a6c664583faa819d4049344b94a14e802f2d2314afcf0d996498a16cd6da8e02b81c1da708f7e021cd0892fd3f4500d831d7a
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
- @job_state = AeActiveJobState::JobState.find_by(active_job_id: job.job_id) ||
21
- AeActiveJobState::JobState.create!(status: 'pending', active_job_id: job.job_id,
22
- args: job.arguments)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AeActiveJobState
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
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.0
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-01-05 00:00:00.000000000 Z
11
+ date: 2021-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aasm