acidic_job 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +6 -6
- data/lib/acidic_job/version.rb +1 -1
- data/lib/acidic_job.rb +3 -3
- 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: 818fce6f9fefae6d2c56930eedcc683f0332f72acbc0ec9b181b1b0855addddb
|
4
|
+
data.tar.gz: 162262b51ac591fee5910b59cda3ebaeb045580e3390f889a37be35212a2a5aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be6dfa507ce2e6cb2e4bb00ae0b57fe7e227d9347ef4a64204c79c52c5b57ec66ec347e37113066b0c4583ddb9c1045fddf3fbf3eacd07942afc528451fa4cd7
|
7
|
+
data.tar.gz: 2c28797e665ce91181a11d20c5cf1183c2cc585cbe5602c5b8dcc870f0403d49c59232d9662b8fcc96926a0082baeea3251bbcb9ac086d6085fffd8d1ad74685
|
data/.github/workflows/main.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -57,14 +57,14 @@ It provides a suite of functionality that empowers you to create complex, robust
|
|
57
57
|
|
58
58
|
### Transactional Steps
|
59
59
|
|
60
|
-
The first and foundational feature `acidic_job` provides is the `
|
60
|
+
The first and foundational feature `acidic_job` provides is the `with_acidity` method, which takes a block of transactional step methods (defined via the `step`) method:
|
61
61
|
|
62
62
|
```ruby
|
63
63
|
class RideCreateJob < ActiveJob::Base
|
64
64
|
include AcidicJob
|
65
65
|
|
66
66
|
def perform(ride_params)
|
67
|
-
|
67
|
+
with_acidity given: { user: current_user, params: ride_params, ride: nil } do
|
68
68
|
step :create_ride_and_audit_record
|
69
69
|
step :create_stripe_charge
|
70
70
|
step :send_receipt
|
@@ -85,20 +85,20 @@ class RideCreateJob < ActiveJob::Base
|
|
85
85
|
end
|
86
86
|
```
|
87
87
|
|
88
|
-
`
|
88
|
+
`with_acidity` takes only the `given:` named parameter and a block where you define the steps of this operation. `step` simply takes the name of a method available in the job. That's all!
|
89
89
|
|
90
90
|
Now, each execution of this job will find or create an `AcidicJob::Key` record, which we leverage to wrap every step in a database transaction. Moreover, this database record allows `acidic_job` to ensure that if your job fails on step 3, when it retries, it will simply jump right back to trying to execute the method defined for the 3rd step, and won't even execute the first two step methods. This means your step methods only need to be idempotent on failure, not on success, since they will never be run again if they succeed.
|
91
91
|
|
92
92
|
### Persisted Attributes
|
93
93
|
|
94
|
-
Any objects passed to the `
|
94
|
+
Any objects passed to the `given` option on the `with_acidity` method are not just made available to each of your step methods, they are made available across retries. This means that you can set an attribute in step 1, access it in step 2, have step 2 fail, have the job retry, jump directly back to step 2 on retry, and have that object still accessible. This is done by serializing all objects to a field on the `AcidicJob::Key` and manually providing getters and setters that sync with the database record.
|
95
95
|
|
96
96
|
```ruby
|
97
97
|
class RideCreateJob < ActiveJob::Base
|
98
98
|
include AcidicJob
|
99
99
|
|
100
100
|
def perform(ride_params)
|
101
|
-
|
101
|
+
with_acidity given: { ride: nil } do
|
102
102
|
step :create_ride_and_audit_record
|
103
103
|
step :create_stripe_charge
|
104
104
|
step :send_receipt
|
@@ -132,7 +132,7 @@ class RideCreateJob < ActiveJob::Base
|
|
132
132
|
include AcidicJob
|
133
133
|
|
134
134
|
def perform(ride_params)
|
135
|
-
|
135
|
+
with_acidity given: { user: current_user, params: ride_params, ride: nil } do
|
136
136
|
step :create_ride_and_audit_record
|
137
137
|
step :create_stripe_charge
|
138
138
|
step :send_receipt
|
data/lib/acidic_job/version.rb
CHANGED
data/lib/acidic_job.rb
CHANGED
@@ -61,7 +61,7 @@ module AcidicJob
|
|
61
61
|
IDEMPOTENCY_KEY_LOCK_TIMEOUT = 90
|
62
62
|
|
63
63
|
# takes a block
|
64
|
-
def
|
64
|
+
def with_acidity(given:)
|
65
65
|
# execute the block to gather the info on what steps are defined for this job workflow
|
66
66
|
steps = yield || []
|
67
67
|
|
@@ -76,7 +76,7 @@ module AcidicJob
|
|
76
76
|
# close proximity, one of the two will be aborted by Postgres because we're
|
77
77
|
# using a transaction with SERIALIZABLE isolation level. It may not look
|
78
78
|
# it, but this code is safe from races.
|
79
|
-
key = ensure_idempotency_key_record(idempotency_key_value, workflow,
|
79
|
+
key = ensure_idempotency_key_record(idempotency_key_value, workflow, given)
|
80
80
|
|
81
81
|
# begin the workflow
|
82
82
|
process_key(key)
|
@@ -180,7 +180,7 @@ module AcidicJob
|
|
180
180
|
raise LockedIdempotencyKey if key.locked_at && key.locked_at > Time.current - IDEMPOTENCY_KEY_LOCK_TIMEOUT
|
181
181
|
|
182
182
|
# Lock the key and update latest run unless the job is already finished.
|
183
|
-
key.update!(last_run_at: Time.current, locked_at: Time.current) unless key.finished?
|
183
|
+
key.update!(last_run_at: Time.current, locked_at: Time.current, workflow: workflow) unless key.finished?
|
184
184
|
else
|
185
185
|
key = Key.create!(
|
186
186
|
idempotency_key: key_val,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acidic_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fractaledmind
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|