pgbus 0.19.2 → 0.19.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 +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +9 -3
- data/app/frontend/pgbus/application.js +4 -3
- data/app/frontend/pgbus/application.min.js +1 -1
- data/app/frontend/pgbus/application.min.js.map +1 -1
- data/app/frontend/pgbus/style.css +1 -1
- data/app/views/layouts/pgbus/application.html.erb +2 -2
- data/lib/pgbus/active_job/adapter.rb +67 -26
- data/lib/pgbus/active_job/batch_id.rb +23 -1
- data/lib/pgbus/batch/builder.rb +1 -0
- data/lib/pgbus/batch.rb +35 -3
- data/lib/pgbus/configuration/snapshot.rb +27 -0
- data/lib/pgbus/integrations/appsignal/event_span.rb +43 -0
- data/lib/pgbus/integrations/appsignal/job_span.rb +47 -0
- data/lib/pgbus/integrations/appsignal/span_subscriber.rb +128 -0
- data/lib/pgbus/integrations/appsignal/subscriber.rb +37 -102
- data/lib/pgbus/shareable.rb +11 -1
- data/lib/pgbus/streams/key.rb +12 -3
- data/lib/pgbus/version.rb +1 -1
- data/lib/pgbus.rb +31 -6
- data/sig/pgbus/configuration/snapshot.rbs +12 -0
- data/sig/pgbus.rbs +1 -0
- metadata +6 -1
data/lib/pgbus.rb
CHANGED
|
@@ -90,6 +90,13 @@ module Pgbus
|
|
|
90
90
|
# Readers need no lock: a reference is published whole.
|
|
91
91
|
attr_reader :loader, :models_loader, :configuration
|
|
92
92
|
|
|
93
|
+
# The settings a non-main Ractor reads (Configuration::Snapshot): a
|
|
94
|
+
# Ractor-shareable copy of the configuration as the last Pgbus.finalize!
|
|
95
|
+
# or Pgbus.configure left it, readable from any Ractor. The defaults until
|
|
96
|
+
# the first finalize, and again after reset!. A setter alone does not
|
|
97
|
+
# publish: the main Ractor reads the configuration itself.
|
|
98
|
+
attr_reader :configuration_snapshot
|
|
99
|
+
|
|
93
100
|
# Process-global flag set by Worker#graceful_shutdown so the adapter
|
|
94
101
|
# can report stopping? to ActiveJob::Continuation (Rails 8.1+).
|
|
95
102
|
def stopping
|
|
@@ -210,20 +217,21 @@ module Pgbus
|
|
|
210
217
|
# configure once a Rails app has booted. While a Rails app boots, the
|
|
211
218
|
# engine's after_initialize finalizes instead, after every initializer
|
|
212
219
|
# and after_initialize block has had its say.
|
|
213
|
-
|
|
220
|
+
finalize_configuration! if configuration.finalized? || !rails_booting?
|
|
214
221
|
configuration
|
|
215
222
|
end
|
|
216
223
|
|
|
217
224
|
# The end of boot: validates the configuration (unless eager_validation
|
|
218
|
-
# is off)
|
|
219
|
-
# (Configuration#finalize!)
|
|
220
|
-
#
|
|
225
|
+
# is off), freezes its plain-data settings into Ractor-shareable values
|
|
226
|
+
# (Configuration#finalize!) and publishes configuration_snapshot for
|
|
227
|
+
# non-main Ractors. Callables and the logger stay as they are, on the main
|
|
228
|
+
# Ractor. Runs on its own: from the engine's after_initialize in a
|
|
221
229
|
# Rails app, at the end of each Pgbus.configure without Rails, and in
|
|
222
230
|
# `pgbus start` after its flags. Call it yourself only when you configure
|
|
223
231
|
# pgbus through setters alone, without Rails.
|
|
224
232
|
def finalize!
|
|
225
233
|
configuration.validate! if configuration.eager_validation
|
|
226
|
-
|
|
234
|
+
finalize_configuration!
|
|
227
235
|
end
|
|
228
236
|
|
|
229
237
|
# Built on first use, under @state_lock: two threads making the first
|
|
@@ -333,6 +341,7 @@ module Pgbus
|
|
|
333
341
|
@client&.close
|
|
334
342
|
@client = nil
|
|
335
343
|
@configuration = Configuration.new
|
|
344
|
+
@configuration_snapshot = Configuration::Snapshot.of(@configuration)
|
|
336
345
|
@stream_cache = Concurrent::Map.new
|
|
337
346
|
end
|
|
338
347
|
end
|
|
@@ -364,11 +373,26 @@ module Pgbus
|
|
|
364
373
|
# Process-local, like the client it holds; replaced (never mutated in
|
|
365
374
|
# place) by reset!/reset_client!.
|
|
366
375
|
attr_reader :stream_cache
|
|
376
|
+
|
|
377
|
+
# Freezes the configuration's plain-data settings and publishes the
|
|
378
|
+
# snapshot non-main Ractors read, unless a reset! replaced the
|
|
379
|
+
# configuration meanwhile (its own snapshot stands) or the snapshot could
|
|
380
|
+
# not be taken (the last one stands).
|
|
381
|
+
def finalize_configuration!
|
|
382
|
+
config = configuration
|
|
383
|
+
config.finalize!
|
|
384
|
+
snapshot = Configuration::Snapshot.of(config)
|
|
385
|
+
@state_lock.synchronize do
|
|
386
|
+
@configuration_snapshot = snapshot if snapshot && @configuration.equal?(config)
|
|
387
|
+
end
|
|
388
|
+
config
|
|
389
|
+
end
|
|
367
390
|
end
|
|
368
391
|
|
|
369
392
|
# Module state, built here at load rather than by `||=` on first use, so no
|
|
370
393
|
# two threads can each build their own (issue #527). @state_lock guards every
|
|
371
|
-
# later write: the client memo, reset!/reset_client!, the stopping flag
|
|
394
|
+
# later write: the client memo, reset!/reset_client!, the stopping flag, the
|
|
395
|
+
# configuration snapshot.
|
|
372
396
|
@state_lock = Mutex.new
|
|
373
397
|
@stopping = false
|
|
374
398
|
@client = nil
|
|
@@ -378,6 +402,7 @@ module Pgbus
|
|
|
378
402
|
|
|
379
403
|
# After loader.setup: Configuration is Zeitwerk-managed.
|
|
380
404
|
@configuration = Configuration.new
|
|
405
|
+
@configuration_snapshot = Configuration::Snapshot.of(@configuration)
|
|
381
406
|
|
|
382
407
|
# In non-Rails contexts, set up model autoloading via a separate loader.
|
|
383
408
|
# This is torn down by the Engine initializer when Rails boots.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module Pgbus
|
|
2
|
+
class Configuration
|
|
3
|
+
# The settings a non-main Ractor reads, as one shareable value
|
|
4
|
+
# (Pgbus.configuration_snapshot).
|
|
5
|
+
class Snapshot < Data
|
|
6
|
+
attr_reader queue_prefix: String
|
|
7
|
+
def self.new: (queue_prefix: String) -> instance
|
|
8
|
+
| (String queue_prefix) -> instance
|
|
9
|
+
def self.of: (Configuration configuration) -> Snapshot?
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
data/sig/pgbus.rbs
CHANGED
|
@@ -57,6 +57,7 @@ module Pgbus
|
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
def self.configuration: () -> Configuration
|
|
60
|
+
def self.configuration_snapshot: () -> Configuration::Snapshot
|
|
60
61
|
def self.configure: () { (Configuration) -> void } -> Configuration
|
|
61
62
|
def self.finalize!: () -> Configuration
|
|
62
63
|
def self.client: () -> Client
|
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.19.
|
|
4
|
+
version: 0.19.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mikael Henriksson
|
|
@@ -329,6 +329,7 @@ files:
|
|
|
329
329
|
- lib/pgbus/configuration/capsule_dsl.rb
|
|
330
330
|
- lib/pgbus/configuration/deploy_settings.rb
|
|
331
331
|
- lib/pgbus/configuration/presence_settings.rb
|
|
332
|
+
- lib/pgbus/configuration/snapshot.rb
|
|
332
333
|
- lib/pgbus/configuration/stream_authorization.rb
|
|
333
334
|
- lib/pgbus/current_attributes.rb
|
|
334
335
|
- lib/pgbus/database_tasks_guard.rb
|
|
@@ -363,7 +364,10 @@ files:
|
|
|
363
364
|
- lib/pgbus/integrations/appsignal/dashboards/pgbus_health.json
|
|
364
365
|
- lib/pgbus/integrations/appsignal/dashboards/pgbus_streams.json
|
|
365
366
|
- lib/pgbus/integrations/appsignal/dashboards/pgbus_throughput.json
|
|
367
|
+
- lib/pgbus/integrations/appsignal/event_span.rb
|
|
368
|
+
- lib/pgbus/integrations/appsignal/job_span.rb
|
|
366
369
|
- lib/pgbus/integrations/appsignal/probe.rb
|
|
370
|
+
- lib/pgbus/integrations/appsignal/span_subscriber.rb
|
|
367
371
|
- lib/pgbus/integrations/appsignal/subscriber.rb
|
|
368
372
|
- lib/pgbus/log_formatter.rb
|
|
369
373
|
- lib/pgbus/mcp.rb
|
|
@@ -515,6 +519,7 @@ files:
|
|
|
515
519
|
- sig/pgbus/active_job/adapter.rbs
|
|
516
520
|
- sig/pgbus/client.rbs
|
|
517
521
|
- sig/pgbus/configuration.rbs
|
|
522
|
+
- sig/pgbus/configuration/snapshot.rbs
|
|
518
523
|
- sig/pgbus/streams.rbs
|
|
519
524
|
- sig/pgbus/streams/stream.rbs
|
|
520
525
|
homepage: https://github.com/zoolutions/pgbus
|