acidic_job 0.8.7 → 0.9.0

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: 153e6365b6a1f1fd5aafca127047a04571c0c9a45f3320c4e17c347b7cbe84b8
4
- data.tar.gz: 94238767a6f1d7066650ac117cdc7eff2cc2aac88f643b697391c411477dc1e1
3
+ metadata.gz: 81f0d07fd3ed80da090cad46ec491cc26eb563daf53409929a35c82cb63205fd
4
+ data.tar.gz: 64de5c5c2ae35b4ce1fc50495b1dd647c722a80075f6371aa62dd7ba6996ebdc
5
5
  SHA512:
6
- metadata.gz: d55ffb8c2888bb83188042a74bf95b90d70dd4c541e92308f7f1e7008f13a63261e635fe280ea1f191fd4f6645e4ed99cfe26c3e63ac3d7b61b60fb1fde9ac0c
7
- data.tar.gz: d773d20887dcf3894bb005a827c8a2ccb80bb1392a34290ddf6cc4e8afaf703b331c56b1246d9059c58900cdc12a23e678b2ef1cc89537878b914a932b9f495c
6
+ metadata.gz: 0fd0a5171079377a1c9e9d810af1e95e955defbe5bb1bd929b627f1b5e66bdea3ae7276728de7369076ad09fd3bf24b23427706f971b69bdb68c912fffdbd14d
7
+ data.tar.gz: 12a1ba218ac52d17bdff46307055a04df317c95600f40eb4391e8d40a8f37169ac3360a8c6fa05657d5c3fb5fac3de92aea8f79b6b81f72604690a63ae4d14cd
data/.rubocop.yml CHANGED
@@ -1,3 +1,7 @@
1
+ require:
2
+ - rubocop-minitest
3
+ - rubocop-rake
4
+
1
5
  AllCops:
2
6
  TargetRubyVersion: 2.7
3
7
  NewCops: enable
@@ -39,3 +43,6 @@ Metrics/PerceivedComplexity:
39
43
 
40
44
  Metrics/ClassLength:
41
45
  Enabled: false
46
+
47
+ Minitest/MultipleAssertions:
48
+ Enabled: false
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 3.1.4
1
+ ruby 3.1.1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acidic_job (0.8.7)
4
+ acidic_job (0.9.0)
5
5
  activejob
6
6
  activerecord
7
7
  activesupport
@@ -85,7 +85,7 @@ module AcidicJob
85
85
  "jid" => @job_id,
86
86
  "queue" => @queue_name
87
87
  }
88
- item["at"] = @scheduled_at if @scheduled_at
88
+ item["at"] = @scheduled_at if defined?(@scheduled_at) && @scheduled_at
89
89
 
90
90
  ::Sidekiq::Client.push(item)
91
91
  end
@@ -126,16 +126,16 @@ module AcidicJob
126
126
  # https://github.com/rails/rails/blob/93c9534c9871d4adad4bc33b5edc355672b59c61/activejob/lib/active_job/callbacks.rb
127
127
  concerning :Callbacks do
128
128
  class_methods do
129
- def around_perform(*filters, &blk)
130
- set_callback(:perform, :around, *filters, &blk)
129
+ def around_perform(...)
130
+ set_callback(:perform, :around, ...)
131
131
  end
132
132
 
133
- def before_perform(*filters, &blk)
134
- set_callback(:perform, :before, *filters, &blk)
133
+ def before_perform(...)
134
+ set_callback(:perform, :before, ...)
135
135
  end
136
136
 
137
- def after_perform(*filters, &blk)
138
- set_callback(:perform, :after, *filters, &blk)
137
+ def after_perform(...)
138
+ set_callback(:perform, :after, ...)
139
139
  end
140
140
  end
141
141
  end
@@ -18,5 +18,13 @@ module AcidicJob
18
18
  rescue ActiveRecord::RecordNotFound
19
19
  nil
20
20
  end
21
+
22
+ # In order to allow our `NewRecordSerializer` a chance to work, we need to ensure that
23
+ # ActiveJob's first attempt to serialize an ActiveRecord model doesn't throw an exception.
24
+ def convert_to_global_id_hash(argument)
25
+ { GLOBALID_KEY => argument.to_global_id.to_s }
26
+ rescue URI::GID::MissingModelIdError
27
+ Serializers.serialize(argument)
28
+ end
21
29
  end
22
30
  end
@@ -16,6 +16,7 @@ module AcidicJob
16
16
  ::ActiveSupport.on_load(:active_job) do
17
17
  ::ActiveJob::Serializers.add_serializers(
18
18
  Serializers::ExceptionSerializer,
19
+ Serializers::NewRecordSerializer,
19
20
  Serializers::FinishedPointSerializer,
20
21
  Serializers::JobSerializer,
21
22
  Serializers::RangeSerializer,
@@ -15,7 +15,7 @@ module AcidicJob
15
15
  STAGED_JOB_ID_PREFIX = "STG"
16
16
  STAGED_JOB_ID_DELIMITER = "__"
17
17
  IDEMPOTENCY_KEY_LOCK_TIMEOUT_SECONDS = 2
18
- RAILS_VERSION = Gem::Version.new(Rails.version)
18
+ RAILS_VERSION = Gem::Version.new(ActiveRecord.version)
19
19
  TARGET_VERSION = Gem::Version.new("7.1")
20
20
  REQUIRES_CODER_FOR_SERIALIZE = RAILS_VERSION >= TARGET_VERSION ||
21
21
  RAILS_VERSION.segments[..1] == TARGET_VERSION.segments
@@ -6,31 +6,36 @@ module AcidicJob
6
6
  module Serializers
7
7
  class ExceptionSerializer < ::ActiveJob::Serializers::ObjectSerializer
8
8
  def serialize(exception)
9
- hash = {
10
- "class" => exception.class.name,
11
- "message" => exception.message,
12
- "cause" => exception.cause,
13
- "backtrace" => {}
14
- }
15
-
16
- exception&.backtrace&.map do |trace|
9
+ compressed_backtrace = {}
10
+ exception.backtrace&.map do |trace|
17
11
  path, _, location = trace.rpartition("/")
12
+ next if compressed_backtrace.key?(path)
18
13
 
19
- next if hash["backtrace"].key?(path)
20
-
21
- hash["backtrace"][path] = location
14
+ compressed_backtrace[path] = location
22
15
  end
16
+ exception.set_backtrace(compressed_backtrace.map do |path, location|
17
+ [path, location].join("/")
18
+ end)
19
+ exception.cause&.set_backtrace([])
23
20
 
24
- super(hash)
21
+ super({ "yaml" => exception.to_yaml })
25
22
  end
26
23
 
27
24
  def deserialize(hash)
28
- exception_class = hash["class"].constantize
29
- exception = exception_class.new(hash["message"])
30
- exception.set_backtrace(hash["backtrace"].map do |path, location|
31
- [path, location].join("/")
32
- end)
33
- exception
25
+ if hash.key?("class")
26
+ exception_class = hash["class"].constantize
27
+ exception = exception_class.new(hash["message"])
28
+ exception.set_backtrace(hash["backtrace"].map do |path, location|
29
+ [path, location].join("/")
30
+ end)
31
+ exception
32
+ elsif hash.key?("yaml")
33
+ if YAML.respond_to?(:unsafe_load)
34
+ YAML.unsafe_load(hash["yaml"])
35
+ else
36
+ YAML.load(hash["yaml"]) # rubocop:disable Security/YAMLLoad
37
+ end
38
+ end
34
39
  end
35
40
 
36
41
  def serialize?(argument)
@@ -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 NewRecordSerializer < ::ActiveJob::Serializers::ObjectSerializer
8
+ def serialize(new_record)
9
+ super(
10
+ "class" => new_record.class.name,
11
+ "attributes" => new_record.attributes
12
+ )
13
+ end
14
+
15
+ def deserialize(hash)
16
+ new_record_class = hash["class"].constantize
17
+ new_record_class.new(hash["attributes"])
18
+ end
19
+
20
+ def serialize?(argument)
21
+ defined?(::ActiveRecord) && argument.respond_to?(:new_record?) && argument.new_record?
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "./testing"
3
+ require_relative "testing"
4
4
 
5
5
  module AcidicJob
6
6
  class TestCase < ::ActiveJob::TestCase
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AcidicJob
4
- VERSION = "0.8.7"
4
+ VERSION = "0.9.0"
5
5
  end
data/lib/acidic_job.rb CHANGED
@@ -30,6 +30,7 @@ require_relative "acidic_job/serializers/range_serializer"
30
30
  require_relative "acidic_job/serializers/recovery_point_serializer"
31
31
  require_relative "acidic_job/serializers/worker_serializer"
32
32
  require_relative "acidic_job/serializers/active_kiq_serializer"
33
+ require_relative "acidic_job/serializers/new_record_serializer"
33
34
 
34
35
  require_relative "acidic_job/railtie"
35
36
 
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.7
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - fractaledmind
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-07 00:00:00.000000000 Z
11
+ date: 2023-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob
@@ -275,6 +275,7 @@ files:
275
275
  - lib/acidic_job/serializers/exception_serializer.rb
276
276
  - lib/acidic_job/serializers/finished_point_serializer.rb
277
277
  - lib/acidic_job/serializers/job_serializer.rb
278
+ - lib/acidic_job/serializers/new_record_serializer.rb
278
279
  - lib/acidic_job/serializers/range_serializer.rb
279
280
  - lib/acidic_job/serializers/recovery_point_serializer.rb
280
281
  - lib/acidic_job/serializers/worker_serializer.rb
@@ -311,7 +312,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
311
312
  - !ruby/object:Gem::Version
312
313
  version: '0'
313
314
  requirements: []
314
- rubygems_version: 3.3.26
315
+ rubygems_version: 3.3.7
315
316
  signing_key:
316
317
  specification_version: 4
317
318
  summary: Idempotent operations for Rails apps, built on top of ActiveJob.