pgbus 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: daac3606ba66624f54b5b6cf8db0830827c2ce0492b7d6d38ce347d1e0f3aeb2
4
- data.tar.gz: ad7eb6ea7beae1e07a813cac5cac37980671f8106f2ac7444a127a81d6f7a2e3
3
+ metadata.gz: cfd2ea5ccec3e3715dbcf2dd409a652527cf1d9e18c60fe4d5797fd5cf5be6ec
4
+ data.tar.gz: 6983d4977aeb792ba0857884752a8b662a15164cde8cd6ee3bb5406d95d7f225
5
5
  SHA512:
6
- metadata.gz: f7a513fd3e2f7aac5a3c0db040a3e7b6b11b6c4c0f619f6f0d37ebbf3e2cd6336737af20e4a7a00da19a1937d5be2b8e24d666483bf661005422c04bbac1805c
7
- data.tar.gz: 255c0382fbc4f4b797577757ebe5bfa9611f350456292d78e41678d6ebe834c52a5588e2f902159b0c5467becb076f0b724b8dc782b21dfb0d423404dc31d178
6
+ metadata.gz: c6f3e19f1e3fe2d5eae02fe52dcd2878f5bbcb13cd7387a41b3902ad91cb8c20ce2d1e3c606488bdce1c901126d1192f7a34747e8746c397d016d0c2541a8828
7
+ data.tar.gz: da5ed5a1a2012d757547e3e2f1f48586a84e7d096df91a793d9ba18f76da881e52dab650d4fb3c605c4da6de06b1e8b58b0d11c99bd90e30ef64b3c368c44093
@@ -57,8 +57,11 @@ module Pgbus
57
57
  end
58
58
 
59
59
  def available_locales
60
- @available_locales ||= Dir[Pgbus::Engine.root.join("config", "locales", "*.yml")]
61
- .map { |f| File.basename(f, ".yml").to_sym }
60
+ @available_locales ||= begin
61
+ pgbus_locales = Dir[Pgbus::Engine.root.join("config", "locales", "*.yml")]
62
+ .map { |f| File.basename(f, ".yml").to_sym }
63
+ pgbus_locales & I18n.available_locales
64
+ end
62
65
  end
63
66
  helper_method :available_locales
64
67
 
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pgbus
4
- class ApplicationRecord < ActiveRecord::Base
4
+ # Backward-compatible alias — host apps that subclassed
5
+ # Pgbus::ApplicationRecord will continue to work.
6
+ # New code should inherit from Pgbus::BusRecord directly.
7
+ class ApplicationRecord < BusRecord
5
8
  self.abstract_class = true
6
9
  end
7
10
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pgbus
4
- class BatchEntry < ApplicationRecord
4
+ class BatchEntry < BusRecord
5
5
  self.table_name = "pgbus_batches"
6
6
 
7
7
  COUNTER_COLUMNS = %w[completed_jobs discarded_jobs].freeze
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pgbus
4
- class BlockedExecution < ApplicationRecord
4
+ class BlockedExecution < BusRecord
5
5
  self.table_name = "pgbus_blocked_executions"
6
6
 
7
7
  scope :for_key, ->(key) { where(concurrency_key: key) }
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pgbus
4
- class JobLock < Pgbus::ApplicationRecord
4
+ class JobLock < BusRecord
5
5
  self.table_name = "pgbus_job_locks"
6
6
 
7
7
  # States:
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pgbus
4
- class JobStat < Pgbus::ApplicationRecord
4
+ class JobStat < BusRecord
5
5
  self.table_name = "pgbus_job_stats"
6
6
 
7
7
  scope :since, ->(time) { where("created_at >= ?", time) }
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pgbus
4
- class OutboxEntry < Pgbus::ApplicationRecord
4
+ class OutboxEntry < BusRecord
5
5
  self.table_name = "pgbus_outbox_entries"
6
6
 
7
7
  scope :unpublished, -> { where(published_at: nil) }
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pgbus
4
- class ProcessEntry < ApplicationRecord
4
+ class ProcessEntry < BusRecord
5
5
  self.table_name = "pgbus_processes"
6
6
 
7
7
  scope :stale, ->(threshold) { where("last_heartbeat_at < ?", threshold) }
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pgbus
4
- class ProcessedEvent < ApplicationRecord
4
+ class ProcessedEvent < BusRecord
5
5
  self.table_name = "pgbus_processed_events"
6
6
 
7
7
  scope :expired, ->(before) { where("processed_at < ?", before) }
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pgbus
4
- class QueueState < Pgbus::ApplicationRecord
4
+ class QueueState < BusRecord
5
5
  self.table_name = "pgbus_queue_states"
6
6
 
7
7
  scope :paused, -> { where(paused: true) }
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pgbus
4
- class RecurringExecution < ApplicationRecord
4
+ class RecurringExecution < BusRecord
5
5
  self.table_name = "pgbus_recurring_executions"
6
6
 
7
7
  validates :task_key, presence: true
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pgbus
4
- class RecurringTask < ApplicationRecord
4
+ class RecurringTask < BusRecord
5
5
  self.table_name = "pgbus_recurring_tasks"
6
6
 
7
7
  validates :key, presence: true, uniqueness: true
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pgbus
4
- class Semaphore < ApplicationRecord
4
+ class Semaphore < BusRecord
5
5
  self.table_name = "pgbus_semaphores"
6
6
 
7
7
  scope :expired, ->(now = Time.current) { where("expires_at < ? OR value <= 0", now) }
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_record"
4
+
5
+ module Pgbus
6
+ # Base class for all Pgbus ActiveRecord models.
7
+ #
8
+ # Lives in lib/pgbus/ so the main Zeitwerk gem loader picks it up
9
+ # regardless of Rails engine boot order. This avoids the NameError
10
+ # that occurs when a host app uses selective railtie requires
11
+ # (require "rails" + individual railties instead of require "rails/all")
12
+ # and the engine's app/models path isn't registered yet.
13
+ class BusRecord < ActiveRecord::Base
14
+ self.abstract_class = true
15
+ end
16
+ end
@@ -201,7 +201,7 @@ module Pgbus
201
201
  connection_params
202
202
  elsif defined?(ActiveRecord::Base)
203
203
  if connects_to
204
- -> { Pgbus::ApplicationRecord.connection.raw_connection }
204
+ -> { Pgbus::BusRecord.connection.raw_connection }
205
205
  else
206
206
  -> { ActiveRecord::Base.connection.raw_connection }
207
207
  end
data/lib/pgbus/engine.rb CHANGED
@@ -27,7 +27,7 @@ module Pgbus
27
27
 
28
28
  initializer "pgbus.db" do
29
29
  ActiveSupport.on_load(:active_record) do
30
- Pgbus::ApplicationRecord.connects_to(**Pgbus.configuration.connects_to) if Pgbus.configuration.connects_to
30
+ Pgbus::BusRecord.connects_to(**Pgbus.configuration.connects_to) if Pgbus.configuration.connects_to
31
31
  end
32
32
  end
33
33
 
@@ -27,7 +27,7 @@ module Pgbus
27
27
  # that share at least one queue with the given queue list,
28
28
  # excluding the current worker (by PID).
29
29
  def self.max_active_priority(queues, my_pid)
30
- conn = Pgbus.configuration.connects_to ? Pgbus::ApplicationRecord.connection : ActiveRecord::Base.connection
30
+ conn = Pgbus.configuration.connects_to ? Pgbus::BusRecord.connection : ActiveRecord::Base.connection
31
31
  rows = conn.select_all(
32
32
  "SELECT metadata FROM pgbus_processes WHERE kind = 'worker' AND pid != $1 AND last_heartbeat_at > $2",
33
33
  "Pgbus ConsumerPriority",
@@ -180,7 +180,7 @@ module Pgbus
180
180
  batch_size = config.archive_compaction_batch_size || 1000
181
181
  prefix = config.queue_prefix
182
182
 
183
- conn = config.connects_to ? Pgbus::ApplicationRecord.connection : ActiveRecord::Base.connection
183
+ conn = config.connects_to ? Pgbus::BusRecord.connection : ActiveRecord::Base.connection
184
184
  queue_names = conn.select_values("SELECT queue_name FROM pgmq.meta ORDER BY queue_name")
185
185
 
186
186
  queue_names.each do |full_name|
@@ -77,7 +77,7 @@ module Pgbus
77
77
 
78
78
  def connection
79
79
  if Pgbus.configuration.connects_to
80
- Pgbus::ApplicationRecord.connection
80
+ Pgbus::BusRecord.connection
81
81
  else
82
82
  ActiveRecord::Base.connection
83
83
  end
@@ -191,7 +191,7 @@ module Pgbus
191
191
  dlq_suffix = config.dead_letter_queue_suffix
192
192
  prefix = "#{config.queue_prefix}_"
193
193
 
194
- conn = Pgbus.configuration.connects_to ? Pgbus::ApplicationRecord.connection : ActiveRecord::Base.connection
194
+ conn = Pgbus.configuration.connects_to ? Pgbus::BusRecord.connection : ActiveRecord::Base.connection
195
195
  all_queues = conn.select_values("SELECT queue_name FROM pgmq.meta ORDER BY queue_name")
196
196
  resolved = all_queues
197
197
  .reject { |q| q.end_with?(dlq_suffix) }
data/lib/pgbus/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pgbus
4
- VERSION = "0.2.4"
4
+ VERSION = "0.2.5"
5
5
  end
@@ -561,7 +561,7 @@ module Pgbus
561
561
  private
562
562
 
563
563
  def connection
564
- Pgbus::ApplicationRecord.connection
564
+ Pgbus::BusRecord.connection
565
565
  end
566
566
 
567
567
  # name is the full PGMQ queue name (already prefixed)
data/lib/pgbus.rb CHANGED
@@ -83,6 +83,10 @@ module Pgbus
83
83
  def logger
84
84
  configuration.logger
85
85
  end
86
+
87
+ def logger=(value)
88
+ configuration.logger = value
89
+ end
86
90
  end
87
91
 
88
92
  loader.setup
@@ -12,7 +12,7 @@ namespace :pgbus do
12
12
  latest = Pgbus::PgmqSchema.latest_version
13
13
  puts "Vendored version: #{latest}"
14
14
 
15
- conn = Pgbus.configuration.connects_to ? Pgbus::ApplicationRecord.connection : ActiveRecord::Base.connection
15
+ conn = Pgbus.configuration.connects_to ? Pgbus::BusRecord.connection : ActiveRecord::Base.connection
16
16
 
17
17
  if conn.table_exists?("pgbus_pgmq_schema_versions")
18
18
  row = conn.select_one(
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgbus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson
@@ -211,6 +211,7 @@ files:
211
211
  - lib/pgbus/active_job/adapter.rb
212
212
  - lib/pgbus/active_job/executor.rb
213
213
  - lib/pgbus/batch.rb
214
+ - lib/pgbus/bus_record.rb
214
215
  - lib/pgbus/circuit_breaker.rb
215
216
  - lib/pgbus/cli.rb
216
217
  - lib/pgbus/client.rb