sidekiq_publisher 3.0.0 → 4.0.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: 8e4cfd9a6432a0e864ad275e0ad4d9ef2e37e7e03e2d60c323d9658ae1ac40bc
4
- data.tar.gz: f0895de91a5bf0b5755835b997bd9ffa64a7b8c659516500eb21401c282b4379
3
+ metadata.gz: 86345d364ea857b29f80ee4f041dd6837c29e5b5a05111497029d461c31d3e7e
4
+ data.tar.gz: 32e159819ce58399eab3cd541e99025f0919cee3e0ccd13a54982638769a6857
5
5
  SHA512:
6
- metadata.gz: bba1eb7da24705acef0140082b509622c96184997a11562d6714f552ddf2fe8aa03840723e5714c677f1e5748e9c640f771245559201084627f2dd271f36d25f
7
- data.tar.gz: '069d74cacc7a2369564402944ae2dfa20b6973fcf4aee7e0d2bbb14bfb207b089aa4b15ae59abea81de2f392bdf480a2b0eadb5790c234ee7cfdf9ed6717fa64'
6
+ metadata.gz: 3a046f7e8a4b39d36215d4676d4467877492cdb26e12cddf5a07a3ff2a52ae78e384657487471a0f0f8443e88cba80583fe53e04914614ef622af8a5b43dfd1e
7
+ data.tar.gz: c75cd6ec9e1d2af0c745da843b962c6eedf47868451e26b6ddddce438043438f44ec25ed023352bf05580a8266487d9d584421108658218b69ba2751a7664a89
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # sidekiq_publisher
2
2
 
3
+ ## 4.0.0
4
+ - BREAKING: Enqueue directly to Redis unless in a transaction ([#74](https://github.com/ezcater/sidekiq_publisher/pull/74/))
5
+
3
6
  ## 3.0.0
4
7
  - BREAKING: Drop support for Ruby `2.6` and `2.7` as they are [past end of life](https://endoflife.date/ruby)
5
8
  - BREAKING: Drop support for `ddtrace <= 1.8.0`
data/README.md CHANGED
@@ -16,6 +16,11 @@ that modifies the system of record for the application. It also allows jobs to
16
16
  be created even when Sidekiq/Redis is temporarily unavailable. The separate
17
17
  publisher process handles retries and ensure that each job is delivered to Sidekiq.
18
18
 
19
+ > :warning: Not all jobs are staged in Postgres. This is determined dynamically:
20
+ > if the job is enqueued from within an `ActiveRecord` transaction, then it is
21
+ > staged in Postgres. If not, then it bypasses Postgres and is enqueued directly
22
+ > to Redis via Sidekiq.
23
+
19
24
  ## Installation
20
25
 
21
26
  Add this line to your application's Gemfile:
@@ -11,19 +11,28 @@ module ActiveJob
11
11
  JOB_WRAPPER_CLASS = ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper.to_s.freeze
12
12
 
13
13
  def enqueue(job)
14
- internal_enqueue(job)
14
+ if SidekiqPublisher::DatabaseConnection.transaction_open?
15
+ create_job_record(job)
16
+ else
17
+ sidekiq_adapter.enqueue(job)
18
+ end
15
19
  end
16
20
 
17
21
  def enqueue_at(job, timestamp)
18
- internal_enqueue(job, timestamp)
22
+ if SidekiqPublisher::DatabaseConnection.transaction_open?
23
+ create_job_record(job, timestamp)
24
+ else
25
+ sidekiq_adapter.enqueue_at(job, timestamp)
26
+ end
19
27
  end
20
28
 
21
29
  private
22
30
 
23
- def internal_enqueue(job, timestamp = nil)
31
+ def create_job_record(job, timestamp = nil)
24
32
  job.provider_job_id = SidekiqPublisher::Job.generate_sidekiq_jid
25
33
  attributes = job_attributes(job)
26
34
  attributes[:run_at] = timestamp if timestamp.present?
35
+
27
36
  SidekiqPublisher::Job.create!(attributes).job_id
28
37
  end
29
38
 
@@ -36,6 +45,10 @@ module ActiveJob
36
45
  args: [job.serialize],
37
46
  }
38
47
  end
48
+
49
+ def sidekiq_adapter
50
+ @_sidekiq_adapter ||= ActiveJob::QueueAdapters::SidekiqAdapter.new
51
+ end
39
52
  end
40
53
  end
41
54
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SidekiqPublisher
4
+ module DatabaseConnection
5
+ def self.transaction_open?
6
+ ActiveRecord::Base.connection.transaction_open?
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SidekiqPublisher
4
- VERSION = "3.0.0"
4
+ VERSION = "4.0.0"
5
5
  end
@@ -10,7 +10,11 @@ module SidekiqPublisher
10
10
 
11
11
  module ClassMethods
12
12
  def client_push(item)
13
- SidekiqPublisher::Job.create_job!(item)
13
+ if SidekiqPublisher::DatabaseConnection.transaction_open?
14
+ SidekiqPublisher::Job.create_job!(item)
15
+ else
16
+ super
17
+ end
14
18
  end
15
19
  end
16
20
  end
@@ -4,6 +4,7 @@ require "active_support"
4
4
  require "active_support/core_ext/numeric/time"
5
5
  require "sidekiq_publisher/version"
6
6
  require "sidekiq_publisher/compatibility"
7
+ require "sidekiq_publisher/database_connection"
7
8
  require "sidekiq_publisher/instrumenter"
8
9
  require "sidekiq_publisher/metrics_reporter"
9
10
  require "sidekiq_publisher/exception_reporter"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq_publisher
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ezCater, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-09 00:00:00.000000000 Z
11
+ date: 2024-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob
@@ -309,6 +309,7 @@ files:
309
309
  - lib/sidekiq_publisher.rb
310
310
  - lib/sidekiq_publisher/client.rb
311
311
  - lib/sidekiq_publisher/compatibility.rb
312
+ - lib/sidekiq_publisher/database_connection.rb
312
313
  - lib/sidekiq_publisher/datadog_apm.rb
313
314
  - lib/sidekiq_publisher/engine.rb
314
315
  - lib/sidekiq_publisher/exception_reporter.rb
@@ -344,7 +345,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
344
345
  - !ruby/object:Gem::Version
345
346
  version: '0'
346
347
  requirements: []
347
- rubygems_version: 3.1.6
348
+ rubygems_version: 3.2.33
348
349
  signing_key:
349
350
  specification_version: 4
350
351
  summary: Publisher for enqueuing jobs to Sidekiq