acidic_job 0.8.0 → 0.8.3

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: a8027a99e7fc6d5602e3269445211abefe4b835f69a7a33b0dea1f70fffec642
4
- data.tar.gz: 6a38451eb30528b774a2a4ee31ac8f2733dea2035c25c3713ecad873c10759c8
3
+ metadata.gz: 0caf8232d94c6dd6eef55378cdf0c57849601185978d04df8f1d2bd91aca04e4
4
+ data.tar.gz: 38ea54d622782ab400fff7c4929be3b77e382440c3de8fdbbf27954a1f5ca98d
5
5
  SHA512:
6
- metadata.gz: ce9eab1470bb0dbc63d92c2b3f8baa124e9f6a5dde95899248376b893a326ba71e6604d5892950677294d1226eb9e2fd8cc658952dee9222dea7c35c0c2f95f3
7
- data.tar.gz: 981613d28454547304c3123250256b74eb80b6af7d3212e138cfbdc3e59c347dfed5c0b96ca95498a511b0391fd893ad0d871ef3dc07939118d3231208370fb3
6
+ metadata.gz: 75c909396867d246923c752d842a43d8a42328b5558bb0733a6e497096df8513e8cf8e8ca1923428fab4e9dc4394df129e543cb49ef512713e9ba1625f2a3741
7
+ data.tar.gz: 88755804b761f066a16232a2fd76c1307273112901869dc7f7984e9646816c5b65543c30e6da119838f1e32c8f1bb080f95367f5bda3ca2e58995e161aba33f4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acidic_job (0.8.0)
4
+ acidic_job (0.8.3)
5
5
  activejob
6
6
  activerecord
7
7
  activesupport
data/README.md CHANGED
@@ -153,9 +153,9 @@ class RideCreateJob < AcidicJob::Base
153
153
  @params = ride_params
154
154
 
155
155
  with_acidic_workflow persisting: { ride: nil } do |workflow|
156
- step :create_ride_and_audit_record, awaits: awaits: [SomeJob.with('argument_1', keyword: 'value'), AnotherJob.with(1, 2, 3, some: 'thing')]
157
- step :create_stripe_charge
158
- step :send_receipt
156
+ workflow.step :create_ride_and_audit_record, awaits: awaits: [SomeJob.with('argument_1', keyword: 'value'), AnotherJob.with(1, 2, 3, some: 'thing')]
157
+ workflow.step :create_stripe_charge
158
+ workflow.step :send_receipt
159
159
  end
160
160
  end
161
161
  end
@@ -172,9 +172,9 @@ class RideCreateJob < AcidicJob::Base
172
172
  @params = ride_params
173
173
 
174
174
  with_acidic_workflow persisting: { ride: nil } do |workflow|
175
- step :create_ride_and_audit_record, awaits: :dynamic_awaits
176
- step :create_stripe_charge
177
- step :send_receipt
175
+ workflow.step :create_ride_and_audit_record, awaits: :dynamic_awaits
176
+ workflow.step :create_stripe_charge
177
+ workflow.step :send_receipt
178
178
  end
179
179
  end
180
180
 
@@ -228,9 +228,9 @@ class RideCreateJob < AcidicJob::Base
228
228
  @params = ride_params
229
229
 
230
230
  with_acidic_workflow persisting: { ride: nil } do |workflow|
231
- step :create_ride_and_audit_record
232
- step :create_stripe_charge
233
- step :send_receipt
231
+ workflow.step :create_ride_and_audit_record
232
+ workflow.step :create_stripe_charge
233
+ workflow.step :send_receipt
234
234
  end
235
235
  end
236
236
 
@@ -264,9 +264,9 @@ class RideCreateJob < AcidicJob::Base
264
264
  @params = ride_params
265
265
 
266
266
  with_acidic_workflow persisting: { ride: nil } do |workflow|
267
- step :create_ride_and_audit_record
268
- step :create_stripe_charge
269
- step :send_receipt
267
+ workflow.step :create_ride_and_audit_record
268
+ workflow.step :create_stripe_charge
269
+ workflow.step :send_receipt
270
270
  end
271
271
  end
272
272
 
@@ -294,11 +294,11 @@ class ExampleJob < AcidicJob::Base
294
294
  end
295
295
  ```
296
296
 
297
- Conversely, a job class can use the `acidic_by_job_args` method to configure that job class to use the arguments passed to the job as the foundation for the job run's idempotency key:
297
+ Conversely, a job class can use the `acidic_by_job_arguments` method to configure that job class to use the arguments passed to the job as the foundation for the job run's idempotency key:
298
298
 
299
299
  ```ruby
300
300
  class ExampleJob < AcidicJob::Base
301
- acidic_by_job_args
301
+ acidic_by_job_arguments
302
302
 
303
303
  def perform(arg_1, arg_2)
304
304
  # the idempotency key will be based on whatever the values of `arg_1` and `arg_2` are
@@ -348,9 +348,9 @@ class RideCreateJob < AcidicJob::Base
348
348
  @params = ride_params
349
349
 
350
350
  with_acidic_workflow persisting: { ride: nil } do |workflow|
351
- step :create_ride_and_audit_record, awaits: [SomeJob.with('argument_1', keyword: 'value')]
352
- step :create_stripe_charge, args: [1, 2, 3], kwargs: { some: 'thing' }
353
- step :send_receipt
351
+ workflow.step :create_ride_and_audit_record, awaits: [SomeJob.with('argument_1', keyword: 'value')]
352
+ workflow.step :create_stripe_charge, args: [1, 2, 3], kwargs: { some: 'thing' }
353
+ workflow.step :send_receipt
354
354
  end
355
355
  end
356
356
 
@@ -18,7 +18,7 @@ module AcidicJob
18
18
  # You could unique job runs by the arguments passed to the job (e.g. memoization)
19
19
  other.define_singleton_method(:acidic_by_job_arguments) { @acidic_identifier = :job_arguments }
20
20
  # Or, you could unique jobs run by any logic you'd like using a block
21
- other.define_singleton_method(:acidic_by) { |&block| @acidic_identifier = block }
21
+ other.define_singleton_method(:acidic_by) { |proc = nil, &block| @acidic_identifier = proc || block }
22
22
 
23
23
  # We add a callback to ensure that staged, non-workflow jobs are "finished" after they are "performed".
24
24
  # This allows us to ensure that we can always inspect whether a run is finished and get correct data
@@ -43,8 +43,12 @@ module AcidicJob
43
43
  # `perform_now` runs a job synchronously and immediately
44
44
  # `perform_later` runs a job asynchronously and queues it immediately
45
45
  # `perform_acidicly` run a job asynchronously and queues it after a successful database commit
46
- def perform_acidicly(*args)
47
- job = new(*args)
46
+ def perform_acidicly(*args, **kwargs)
47
+ job = if kwargs.empty?
48
+ new(*args)
49
+ else
50
+ new(*args, **kwargs)
51
+ end
48
52
 
49
53
  Run.stage!(job)
50
54
  end
@@ -73,8 +77,7 @@ module AcidicJob
73
77
  end
74
78
 
75
79
  def with_acidic_workflow(persisting: {}, &block)
76
- raise UnknownJobAdapter unless (defined?(::AcidicJob::Base) && self.class < ::AcidicJob::Base) ||
77
- (defined?(::AcidicJob::ActiveKiq) && self.class < ::AcidicJob::ActiveKiq)
80
+ raise UnknownJobAdapter unless known_job_adapter?
78
81
 
79
82
  raise RedefiningWorkflow if defined? @workflow_builder
80
83
 
@@ -246,5 +249,13 @@ module AcidicJob
246
249
  :serializable
247
250
  end
248
251
  end
252
+
253
+ def known_job_adapter?
254
+ return true if defined?(::AcidicJob::Base) && self.class < ::AcidicJob::Base
255
+ return true if defined?(::AcidicJob::ActiveKiq) && self.class < ::AcidicJob::ActiveKiq
256
+ return true if defined?(::ActiveJob) && self.class < ::ActiveJob::Base
257
+
258
+ false
259
+ end
249
260
  end
250
261
  end
@@ -8,9 +8,9 @@ module AcidicJob
8
8
  @arguments = args
9
9
 
10
10
  # we don't want to run the `perform` callbacks twice, since ActiveJob already handles that for us
11
- if defined?(ActiveJob) && self.class < ActiveJob::Base
11
+ if defined?(::ActiveJob) && self.class < ::ActiveJob::Base
12
12
  super(*args)
13
- elsif defined?(Sidekiq) && self.class.include?(Sidekiq::Worker)
13
+ elsif defined?(::Sidekiq) && self.class.include?(::Sidekiq::Worker)
14
14
  run_callbacks :perform do
15
15
  super(*args)
16
16
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AcidicJob
4
- VERSION = "0.8.0"
4
+ VERSION = "0.8.3"
5
5
  end
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.8.0
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - fractaledmind
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-16 00:00:00.000000000 Z
11
+ date: 2022-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob