acidic_job 0.8.3 → 0.8.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: 0caf8232d94c6dd6eef55378cdf0c57849601185978d04df8f1d2bd91aca04e4
4
- data.tar.gz: 38ea54d622782ab400fff7c4929be3b77e382440c3de8fdbbf27954a1f5ca98d
3
+ metadata.gz: 041e2488af3dc4780e6112b92195dc805063ebc4c631bd3d7012017efe4e1583
4
+ data.tar.gz: d035a4d739e3cc7b6f6a2f223aefa7d600ab67dae537814363f16a478dd8c00c
5
5
  SHA512:
6
- metadata.gz: 75c909396867d246923c752d842a43d8a42328b5558bb0733a6e497096df8513e8cf8e8ca1923428fab4e9dc4394df129e543cb49ef512713e9ba1625f2a3741
7
- data.tar.gz: 88755804b761f066a16232a2fd76c1307273112901869dc7f7984e9646816c5b65543c30e6da119838f1e32c8f1bb080f95367f5bda3ca2e58995e161aba33f4
6
+ metadata.gz: 96792f3e03f71aa19a83773a3eded77de541e6ea72c9aa2ca421f5298aa5e0e234b0705b0a27f417ebdb02b8e0b621ab935571b5ffc728a729c22bff7f97d809
7
+ data.tar.gz: 7dc53950ebf1d1c425f02f2c12a065cefa71c8c57173a4aa27478d9fcab7ffc0cdc822034da9179d59da9a0c544bd8b7c81108ef4da99a941de4b1d9ec63eb28
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acidic_job (0.8.3)
4
+ acidic_job (0.8.4)
5
5
  activejob
6
6
  activerecord
7
7
  activesupport
data/README.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # AcidicJob
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/acidic_job.svg)](https://badge.fury.io/rb/acidic_job)
4
- ![main workflow](https://github.com/fractaledmind/acidic_job/actions/workflows/main.yml/badge.svg)
3
+ [![Gem Version](https://badge.fury.io/rb/acidic_job.svg)](https://rubygems.org/gems/acidic_job)
4
+ [![Gem Downloads](https://img.shields.io/gem/dt/acidic_job)](https://rubygems.org/gems/acidic_job)
5
+ ![Tests](https://github.com/fractaledmind/acidic_job/actions/workflows/main.yml/badge.svg)
6
+ ![Coverage](https://img.shields.io/badge/code%20coverage-98%25-success)
7
+ [![Codacy Badge](https://app.codacy.com/project/badge/Grade/e0df63f7a6f141d4aecc3c477314fdb2)](https://www.codacy.com/gh/fractaledmind/acidic_job/dashboard?utm_source=github.com&utm_medium=referral&utm_content=fractaledmind/acidic_job&utm_campaign=Badge_Grade)
5
8
 
6
9
  ## Idempotent operations for Rails apps (for ActiveJob or Sidekiq)
7
10
 
@@ -306,24 +309,22 @@ class ExampleJob < AcidicJob::Base
306
309
  end
307
310
  ```
308
311
 
309
- These options cover the two common situations, but sometimes our systems need finer-grained control. For example, our job might take some record as the job argument, but we need to use a combination of the record identifier and record status as the foundation for the idempotency key. In these cases you can pass a `Proc` to an `acidic_by` class method:
312
+ These options cover the two common situations, but sometimes our systems need finer-grained control. For example, our job might take some record as the job argument, but we need to use a combination of the record identifier and record status as the foundation for the idempotency key. In these cases you can pass a `Proc` or a `Block` to an `acidic_by` class method. This code will be executed in the context of the newly initialized job instance, so you will have access to whatever data the job is initialized with (like the `arguments`, for example):
310
313
 
311
314
  ```ruby
312
315
  class ExampleJob < AcidicJob::Base
313
- acidic_by -> { [@record.id, @record.status] }
316
+ acidic_by do
317
+ record = arguments.first[:record]
318
+ [record.id, record.status]
319
+ end
314
320
 
315
321
  def perform(record:)
316
- @record = record
317
-
318
- # the idempotency key will be based on whatever the values of `@record.id` and `@record.status` are
319
- with_acidic_workflow do |workflow|
320
- workflow.step :do_something
321
- end
322
+ # ...
322
323
  end
323
324
  end
324
325
  ```
325
326
 
326
- > **Note:** The `acidic_by` proc _will be executed in the context of the job instance_ at the moment the `with_acidic_workflow` method is called. This means it will have access to any instance variables defined in your `perform` method up to that point.
327
+ > **Note:** The `acidic_by` proc/block _will be executed in the context of the job instance_ at the moment the job is initialized. This means it will **not** have access to any instance variables defined in your `perform` method.
327
328
 
328
329
 
329
330
  ### Sidekiq Callbacks
@@ -20,14 +20,17 @@ module AcidicJob
20
20
  Serializers::JobSerializer,
21
21
  Serializers::RangeSerializer,
22
22
  Serializers::RecoveryPointSerializer,
23
- Serializers::WorkerSerializer
23
+ Serializers::WorkerSerializer,
24
+ Serializers::ActiveKiqSerializer
24
25
  )
25
26
  end
26
27
  end
27
28
 
29
+ # :nocov:
28
30
  generators do
29
31
  require "generators/acidic_job/install_generator"
30
32
  end
33
+ # :nocov:
31
34
 
32
35
  # This hook happens after all initializers are run, just before returning
33
36
  config.after_initialize do
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_job/serializers/object_serializer"
4
+
5
+ module AcidicJob
6
+ module Serializers
7
+ class ActiveKiqSerializer < ::ActiveJob::Serializers::ObjectSerializer
8
+ def serialize(worker)
9
+ super(
10
+ "job_class" => worker.class.name,
11
+ "arguments" => Arguments.serialize(worker.arguments),
12
+ )
13
+ end
14
+
15
+ def deserialize(hash)
16
+ worker_class = hash["job_class"].constantize
17
+ worker_class.new(*hash["arguments"])
18
+ end
19
+
20
+ def serialize?(argument)
21
+ defined?(::AcidicJob::ActiveKiq) && argument.class < ::AcidicJob::ActiveKiq
22
+ end
23
+ end
24
+ end
25
+ end
@@ -13,7 +13,7 @@ module AcidicJob
13
13
  "backtrace" => {}
14
14
  }
15
15
 
16
- exception.backtrace.map do |trace|
16
+ exception&.backtrace&.map do |trace|
17
17
  path, _, location = trace.rpartition("/")
18
18
 
19
19
  next if hash["backtrace"].key?(path)
@@ -10,7 +10,7 @@ module AcidicJob
10
10
  # by comparing the deserialized database value with a temporary in-memory generated value.
11
11
  # That temporary in-memory generated value can sometimes have an `enqueued_at` value that is 1 second off
12
12
  # from the original. In this case, ActiveRecord will think the record has unsaved changes and block the lock.
13
- super(job.as_json.merge("job_class" => job.class.name))
13
+ super(job.serialize.except("enqueued_at"))
14
14
  end
15
15
 
16
16
  def deserialize(hash)
@@ -2,26 +2,24 @@
2
2
 
3
3
  require "active_job/serializers/object_serializer"
4
4
 
5
- # :nocov:
6
5
  module AcidicJob
7
6
  module Serializers
8
7
  class WorkerSerializer < ::ActiveJob::Serializers::ObjectSerializer
9
8
  def serialize(worker)
10
9
  super(
11
- "job_class" => worker.class.name,
12
- "arguments" => worker.arguments,
10
+ "job_class" => worker.class.name
13
11
  )
14
12
  end
15
13
 
16
14
  def deserialize(hash)
17
15
  worker_class = hash["job_class"].constantize
18
- worker_class.new(*hash["arguments"])
16
+ worker_class.new
19
17
  end
20
18
 
21
19
  def serialize?(argument)
22
- defined?(::Sidekiq) && argument.class.include?(::Sidekiq::Worker)
20
+ defined?(::Sidekiq) && argument.class.include?(::Sidekiq::Worker) &&
21
+ !(defined?(::AcidicJob::ActiveKiq) && argument.class < ::AcidicJob::ActiveKiq)
23
22
  end
24
23
  end
25
24
  end
26
25
  end
27
- # :nocov:
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AcidicJob
4
- VERSION = "0.8.3"
4
+ VERSION = "0.8.4"
5
5
  end
data/lib/acidic_job.rb CHANGED
@@ -27,6 +27,7 @@ require_relative "acidic_job/serializers/job_serializer"
27
27
  require_relative "acidic_job/serializers/range_serializer"
28
28
  require_relative "acidic_job/serializers/recovery_point_serializer"
29
29
  require_relative "acidic_job/serializers/worker_serializer"
30
+ require_relative "acidic_job/serializers/active_kiq_serializer"
30
31
 
31
32
  require_relative "acidic_job/rails"
32
33
 
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.3
4
+ version: 0.8.4
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-17 00:00:00.000000000 Z
11
+ date: 2022-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob
@@ -266,6 +266,7 @@ files:
266
266
  - lib/acidic_job/recovery_point.rb
267
267
  - lib/acidic_job/run.rb
268
268
  - lib/acidic_job/serializer.rb
269
+ - lib/acidic_job/serializers/active_kiq_serializer.rb
269
270
  - lib/acidic_job/serializers/exception_serializer.rb
270
271
  - lib/acidic_job/serializers/finished_point_serializer.rb
271
272
  - lib/acidic_job/serializers/job_serializer.rb