pgbus 0.1.3 → 0.1.4

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: 69a6790c65867a2b802baeb5063ddaa9f2ca2037699e8c66a321c46ecbeed955
4
- data.tar.gz: 439beda605c50814124b96891529e81e1deab4fe6f035c2ec669010646892247
3
+ metadata.gz: 5b8f740d2e7c3b561a9591c94d08aef98b22566a3f56517c3055e4fab2c76f98
4
+ data.tar.gz: a6ee24b79ade13317966dee815a49c1d03b2b290dd7635751fa070216fee7d0b
5
5
  SHA512:
6
- metadata.gz: 96c36a79b909568c58d2072b4a2c15914939a6667386ec7811a67b7b3f1dab26f148b78bfb42d40afcc8cde821c2d8b0abcf1c1012f22c4caeeb15ab60a383b9
7
- data.tar.gz: d5a2a508308a08948f66294ecf351563fa63d24abe4fde8e62c1265846b6e00b264f277a972da3b41c024ece3201fed5b12be79db206995f2435b811abe35ea7
6
+ metadata.gz: 4df75c29bc7aa63b4a37b6425f9adf333d0986225ee99d65b33a125fd12c23f03a4000b5a38a610c39c46608622cb4dce5998864dff16942aa223d0671f006bf
7
+ data.tar.gz: a8da2aafd4259b0a73502201aad5542ca31a8d7299e9b84e6e62f3413d62582febd947e1b748024fd09975d1e9b8d2efd16601b278367d6a69feb6e8456ad6d0
@@ -137,7 +137,11 @@ module Pgbus
137
137
  elsif connection_params
138
138
  connection_params
139
139
  elsif defined?(ActiveRecord::Base)
140
- -> { ActiveRecord::Base.connection.raw_connection }
140
+ if connects_to
141
+ -> { Pgbus::ApplicationRecord.connection.raw_connection }
142
+ else
143
+ -> { ActiveRecord::Base.connection.raw_connection }
144
+ end
141
145
  else
142
146
  raise ConfigurationError, "No database connection configured. " \
143
147
  "Set Pgbus.configuration.database_url, connection_params, or use with Rails."
data/lib/pgbus/engine.rb CHANGED
@@ -6,6 +6,12 @@ module Pgbus
6
6
  class Engine < ::Rails::Engine
7
7
  isolate_namespace Pgbus
8
8
 
9
+ # When pgbus was loaded before Rails, a separate Zeitwerk loader manages
10
+ # app/models. Tear it down before Rails' autoloader claims the same paths.
11
+ initializer "pgbus.release_models_loader", before: :set_autoload_paths do
12
+ Pgbus.teardown_models_loader!
13
+ end
14
+
9
15
  initializer "pgbus.configure" do |app|
10
16
  config_path = app.root.join("config", "pgbus.yml")
11
17
  Pgbus::ConfigLoader.load(config_path) if config_path.exist?
@@ -107,7 +107,8 @@ module Pgbus
107
107
  dlq_suffix = config.dead_letter_queue_suffix
108
108
  prefix = "#{config.queue_prefix}_"
109
109
 
110
- all_queues = ActiveRecord::Base.connection.select_values("SELECT queue_name FROM pgmq.meta ORDER BY queue_name")
110
+ conn = Pgbus.configuration.connects_to ? Pgbus::ApplicationRecord.connection : ActiveRecord::Base.connection
111
+ all_queues = conn.select_values("SELECT queue_name FROM pgmq.meta ORDER BY queue_name")
111
112
  resolved = all_queues
112
113
  .reject { |q| q.end_with?(dlq_suffix) }
113
114
  .map { |q| q.delete_prefix(prefix) }
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.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
data/lib/pgbus.rb CHANGED
@@ -18,16 +18,33 @@ module Pgbus
18
18
  loader.inflector.inflect("pgbus" => "Pgbus", "cli" => "CLI", "dsl" => "DSL")
19
19
  loader.ignore("#{__dir__}/generators")
20
20
  loader.ignore("#{__dir__}/active_job")
21
- # Register app/models for non-Rails usage (specs, standalone).
22
- # When Rails is running, the Engine handles autoloading app/models.
23
- unless defined?(Rails::Engine)
24
- models_dir = File.expand_path("../app/models", __dir__)
25
- loader.push_dir(models_dir) if File.directory?(models_dir)
26
- end
27
21
  loader
28
22
  end
29
23
  end
30
24
 
25
+ # Separate loader for app/models used only in non-Rails contexts (specs,
26
+ # standalone scripts). When the Engine boots, Rails' autoloader takes over
27
+ # app/models and this loader is torn down to avoid conflicts.
28
+ def models_loader
29
+ models_dir = File.expand_path("../app/models", __dir__)
30
+ return nil unless File.directory?(models_dir)
31
+
32
+ @models_loader ||= begin
33
+ loader = Zeitwerk::Loader.new
34
+ loader.tag = "pgbus-models"
35
+ loader.push_dir(models_dir)
36
+ loader.setup
37
+ loader
38
+ end
39
+ end
40
+
41
+ def teardown_models_loader!
42
+ return unless @models_loader
43
+
44
+ @models_loader.unregister
45
+ @models_loader = nil
46
+ end
47
+
31
48
  def configuration
32
49
  @configuration ||= Configuration.new
33
50
  end
@@ -52,6 +69,10 @@ module Pgbus
52
69
  end
53
70
 
54
71
  loader.setup
72
+
73
+ # In non-Rails contexts, set up model autoloading via a separate loader.
74
+ # This is torn down by the Engine initializer when Rails boots.
75
+ models_loader unless defined?(Rails::Engine)
55
76
  end
56
77
 
57
78
  require "active_job/queue_adapters/pgbus_adapter" if defined?(ActiveJob)
@@ -12,8 +12,10 @@ namespace :pgbus do
12
12
  latest = Pgbus::PgmqSchema.latest_version
13
13
  puts "Vendored version: #{latest}"
14
14
 
15
- if ActiveRecord::Base.connection.table_exists?("pgbus_pgmq_schema_versions")
16
- row = ActiveRecord::Base.connection.select_one(
15
+ conn = Pgbus.configuration.connects_to ? Pgbus::ApplicationRecord.connection : ActiveRecord::Base.connection
16
+
17
+ if conn.table_exists?("pgbus_pgmq_schema_versions")
18
+ row = conn.select_one(
17
19
  "SELECT version, install_method, installed_at FROM pgbus_pgmq_schema_versions ORDER BY installed_at DESC LIMIT 1"
18
20
  )
19
21
  if row
@@ -32,7 +34,7 @@ namespace :pgbus do
32
34
  end
33
35
  else
34
36
  # Check if pgmq schema exists at all
35
- schema_exists = ActiveRecord::Base.connection.select_value(
37
+ schema_exists = conn.select_value(
36
38
  "SELECT 1 FROM information_schema.schemata WHERE schema_name = 'pgmq'"
37
39
  )
38
40
  if schema_exists
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.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson