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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +12 -11
- data/lib/acidic_job/rails.rb +4 -1
- data/lib/acidic_job/serializers/active_kiq_serializer.rb +25 -0
- data/lib/acidic_job/serializers/exception_serializer.rb +1 -1
- data/lib/acidic_job/serializers/job_serializer.rb +1 -1
- data/lib/acidic_job/serializers/worker_serializer.rb +4 -6
- data/lib/acidic_job/version.rb +1 -1
- data/lib/acidic_job.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 041e2488af3dc4780e6112b92195dc805063ebc4c631bd3d7012017efe4e1583
|
4
|
+
data.tar.gz: d035a4d739e3cc7b6f6a2f223aefa7d600ab67dae537814363f16a478dd8c00c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96792f3e03f71aa19a83773a3eded77de541e6ea72c9aa2ca421f5298aa5e0e234b0705b0a27f417ebdb02b8e0b621ab935571b5ffc728a729c22bff7f97d809
|
7
|
+
data.tar.gz: 7dc53950ebf1d1c425f02f2c12a065cefa71c8c57173a4aa27478d9fcab7ffc0cdc822034da9179d59da9a0c544bd8b7c81108ef4da99a941de4b1d9ec63eb28
|
data/Gemfile.lock
CHANGED
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://
|
4
|
-
![
|
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
|
316
|
+
acidic_by do
|
317
|
+
record = arguments.first[:record]
|
318
|
+
[record.id, record.status]
|
319
|
+
end
|
314
320
|
|
315
321
|
def perform(record:)
|
316
|
-
|
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
|
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
|
data/lib/acidic_job/rails.rb
CHANGED
@@ -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
|
@@ -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.
|
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
|
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:
|
data/lib/acidic_job/version.rb
CHANGED
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.
|
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-
|
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
|