acidic_job 0.7.1 → 0.7.5

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: 970e9128c668bd3d5950a517eae9c215ee6c85d4d56a69fc8862afc622046df2
4
- data.tar.gz: e04595bedefa12976e37661b34cb04544966af203c92df88a943e11667bab23f
3
+ metadata.gz: 0ce6a143a80bd88434c13eb9efe757511d5bc5a4eebdb60cd7b00cab5e9ccf91
4
+ data.tar.gz: 299938e0eac7f16ecf8b2090ccd2f3c8e019be091558c5774b6b3673990eeb11
5
5
  SHA512:
6
- metadata.gz: d95c1a6446e528300fb0d61ce45c897796ecca97af639a9f76a7375b39bd4332e7011d93663738a8eae08f93ae896b5663522ca372eddbf93d106eec79430db5
7
- data.tar.gz: 550c9c53c6bde0b1b572ed3e0e98d470b78af0cdc0b1e2a50294ec7c3432421de64b01389df9c43f2e2fe24430d38de94c67d3be8f58660fc182130453ae73a5
6
+ metadata.gz: e0ee67654ff2ab8aaa4739372d1692cc98c7cfb9c5a0ce1be1383f02421af3f6833ef7622c3a61a0677a37cdb3f1f38665bd07ccaa7adc204ed0e0e7f07f514f
7
+ data.tar.gz: 7b82050bb354ce05e4f0ee769b690f30fcd4a29dbb2382d9328b59fe32d9fec8b61b2e79e3bf4a508b5a59e5f6265024cb0c9e8dcfa85e861f1b3e3a2e8d5ea5
@@ -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.1)
4
+ acidic_job (0.7.5)
5
5
  activerecord (>= 4.0.0)
6
6
  activesupport
7
7
 
@@ -62,8 +62,6 @@ GEM
62
62
  nokogiri (1.12.3)
63
63
  mini_portile2 (~> 2.6.1)
64
64
  racc (~> 1.4)
65
- nokogiri (1.12.3-x86_64-darwin)
66
- racc (~> 1.4)
67
65
  parallel (1.20.1)
68
66
  parser (3.0.1.1)
69
67
  ast (~> 2.4.1)
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
@@ -2,7 +2,8 @@
2
2
 
3
3
  module AcidicJob
4
4
  module DeliverTransactionallyExtension
5
- def deliver_transactionally(options = {})
5
+ # rubocop:disable Metrics/MethodLength
6
+ def deliver_transactionally(_options = {})
6
7
  job = delivery_job_class
7
8
 
8
9
  attributes = {
@@ -11,14 +12,15 @@ module AcidicJob
11
12
  }
12
13
 
13
14
  job_args = if job <= ActionMailer::Parameterized::MailDeliveryJob
14
- [@mailer_class.name, @action.to_s, "deliver_now", {params: @params, args: @args}]
15
- else
16
- [@mailer_class.name, @action.to_s, "deliver_now", @params, *@args]
17
- end
15
+ [@mailer_class.name, @action.to_s, "deliver_now", { params: @params, args: @args }]
16
+ else
17
+ [@mailer_class.name, @action.to_s, "deliver_now", @params, *@args]
18
+ end
18
19
 
19
20
  attributes[:job_args] = job.new(job_args).serialize
20
21
 
21
22
  AcidicJob::Staged.create!(attributes)
22
23
  end
24
+ # rubocop:enable Metrics/MethodLength
23
25
  end
24
26
  end
@@ -18,7 +18,6 @@ module AcidicJob
18
18
 
19
19
  private
20
20
 
21
- # rubocop:disable Metrics/AbcSize
22
21
  def set_arguments_for_perform(*args, **kwargs)
23
22
  # store arguments passed into `perform` so that we can later persist
24
23
  # them to `AcidicJob::Key#job_args` for both ActiveJob and Sidekiq::Worker
@@ -32,6 +31,5 @@ module AcidicJob
32
31
  []
33
32
  end
34
33
  end
35
- # rubocop:enable Metrics/AbcSize
36
34
  end
37
35
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AcidicJob
4
- VERSION = "0.7.1"
4
+ VERSION = "0.7.5"
5
5
  end
data/lib/acidic_job.rb CHANGED
@@ -25,9 +25,7 @@ module AcidicJob
25
25
  # Extend ActiveJob with `perform_transactionally` class method
26
26
  klass.include PerformTransactionallyExtension
27
27
 
28
- if defined?(ActionMailer)
29
- ActionMailer::Parameterized::MessageDelivery.include DeliverTransactionallyExtension
30
- end
28
+ ActionMailer::Parameterized::MessageDelivery.include DeliverTransactionallyExtension if defined?(ActionMailer)
31
29
 
32
30
  # Ensure our `perform` method always runs first to gather parameters
33
31
  klass.prepend PerformWrapper
@@ -63,7 +61,7 @@ module AcidicJob
63
61
  IDEMPOTENCY_KEY_LOCK_TIMEOUT = 90
64
62
 
65
63
  # takes a block
66
- def idempotently(with:)
64
+ def with_acidity(given:)
67
65
  # execute the block to gather the info on what steps are defined for this job workflow
68
66
  steps = yield || []
69
67
 
@@ -78,11 +76,12 @@ module AcidicJob
78
76
  # close proximity, one of the two will be aborted by Postgres because we're
79
77
  # using a transaction with SERIALIZABLE isolation level. It may not look
80
78
  # it, but this code is safe from races.
81
- key = ensure_idempotency_key_record(idempotency_key_value, workflow, with)
79
+ key = ensure_idempotency_key_record(idempotency_key_value, workflow, given)
82
80
 
83
81
  # begin the workflow
84
82
  process_key(key)
85
83
  end
84
+ alias_method :idempotently, :with_acidity
86
85
 
87
86
  def process_key(key)
88
87
  @key = key
@@ -95,7 +94,7 @@ module AcidicJob
95
94
  recovery_point = @key.recovery_point.to_s
96
95
  current_step = @key.workflow[recovery_point]
97
96
 
98
- if recovery_point == Key::RECOVERY_POINT_FINISHED.to_s
97
+ if recovery_point == Key::RECOVERY_POINT_FINISHED.to_s # rubocop:disable Style/GuardClause
99
98
  break
100
99
  elsif current_step.nil?
101
100
  raise UnknownRecoveryPoint, "Defined workflow does not reference this step: #{recovery_point}"
@@ -182,7 +181,7 @@ module AcidicJob
182
181
  raise LockedIdempotencyKey if key.locked_at && key.locked_at > Time.current - IDEMPOTENCY_KEY_LOCK_TIMEOUT
183
182
 
184
183
  # Lock the key and update latest run unless the job is already finished.
185
- key.update!(last_run_at: Time.current, locked_at: Time.current) unless key.finished?
184
+ key.update!(last_run_at: Time.current, locked_at: Time.current, workflow: workflow) unless key.finished?
186
185
  else
187
186
  key = Key.create!(
188
187
  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.1
4
+ version: 0.7.5
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-16 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