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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7dd5ef2a75562917c4bc4340c794ba8d0bfe8cd16e16f87648281e55915cc415
4
- data.tar.gz: beccac205aeac449f163a3474b0f0d906b0331a8f5495c3f48883378c3d08392
3
+ metadata.gz: 818fce6f9fefae6d2c56930eedcc683f0332f72acbc0ec9b181b1b0855addddb
4
+ data.tar.gz: 162262b51ac591fee5910b59cda3ebaeb045580e3390f889a37be35212a2a5aa
5
5
  SHA512:
6
- metadata.gz: 8bef8f4e65efa86de60a3d44bdf2cfff86593a6da6bd7f6cc0c7261272b8fdb775f95bfee2990c1f7d03681fe182b1b54bbe8449cf068b8a97f2d54144b75bec
7
- data.tar.gz: b5ad802967a4f5096fcffd6ee682c429d70194b9c4b549e2542fcc7be8206e0e3b7111824815c2f207504307af4a644bd81020a5be3ac6416728bebafa8c1c84
6
+ metadata.gz: be6dfa507ce2e6cb2e4bb00ae0b57fe7e227d9347ef4a64204c79c52c5b57ec66ec347e37113066b0c4583ddb9c1045fddf3fbf3eacd07942afc528451fa4cd7
7
+ data.tar.gz: 2c28797e665ce91181a11d20c5cf1183c2cc585cbe5602c5b8dcc870f0403d49c59232d9662b8fcc96926a0082baeea3251bbcb9ac086d6085fffd8d1ad74685
@@ -13,6 +13,6 @@ jobs:
13
13
  ruby-version: 2.7.1
14
14
  - name: Run the default task
15
15
  run: |
16
- gem install bundler -v 2.2.5
16
+ gem install bundler -v 2.2.31
17
17
  bundle install
18
18
  bundle exec rake
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acidic_job (0.7.3)
4
+ acidic_job (0.7.4)
5
5
  activerecord (>= 4.0.0)
6
6
  activesupport
7
7
 
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 `idempotently` method, which takes a block of transactional step methods (defined via the `step`) method:
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
- idempotently with: { user: current_user, params: ride_params, ride: nil } do
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
- `idempotently` takes only the `with:` 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!
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 `with` option on the `idempotently` 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.
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
- idempotently with: { ride: nil } do
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
- idempotently with: { user: current_user, params: ride_params, ride: nil } do
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AcidicJob
4
- VERSION = "0.7.3"
4
+ VERSION = "0.7.4"
5
5
  end
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 idempotently(with:)
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, with)
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.3
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-17 00:00:00.000000000 Z
11
+ date: 2021-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord