pgbus 0.8.0 → 0.8.1
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/lib/pgbus/client/notify_stream.rb +1 -1
- data/lib/pgbus/configuration.rb +15 -1
- data/lib/pgbus/streams.rb +6 -2
- data/lib/pgbus/version.rb +1 -1
- data/lib/pgbus.rb +8 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f4ffab2bc9e16f1f6dd6c268a1e1019d768c916ea397064fc66c0f4938ce6e5a
|
|
4
|
+
data.tar.gz: ea2bfeb2bccc34b532facace227159cd0fa550d7ceb8c2ab57e48fa6a9a9020c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cbce8e9eb0243c5875f4d39ce55dd47b9eda9043959dbc833bd3a2ac7e1470bdb299d042e2394b747c59be45177ff9fdb349f1126f360e70a78b1c03dd2db90f
|
|
7
|
+
data.tar.gz: 6d46db3bd53e2f230a43fb89496f744976910a2f64540fbfde956e0d5661a808fcfc586a6a552fe114e6b716ff288e7d310651eb2f05ef381ee058e9d0180e60
|
|
@@ -26,7 +26,7 @@ module Pgbus
|
|
|
26
26
|
|
|
27
27
|
Instrumentation.instrument("pgbus.stream.notify", stream: stream_name, bytes: json.bytesize) do
|
|
28
28
|
synchronized do
|
|
29
|
-
@pgmq.with_connection do |conn|
|
|
29
|
+
@pgmq.__send__(:with_connection) do |conn|
|
|
30
30
|
conn.exec_params("SELECT pg_notify($1, $2)", [channel, json])
|
|
31
31
|
end
|
|
32
32
|
end
|
data/lib/pgbus/configuration.rb
CHANGED
|
@@ -105,7 +105,8 @@ module Pgbus
|
|
|
105
105
|
:streams_max_connections, :streams_idle_timeout, :streams_listen_health_check_ms,
|
|
106
106
|
:streams_write_deadline_ms, :streams_falcon_streaming_body,
|
|
107
107
|
:streams_stats_enabled, :streams_test_mode,
|
|
108
|
-
:streams_orphan_sweep_interval, :streams_orphan_threshold
|
|
108
|
+
:streams_orphan_sweep_interval, :streams_orphan_threshold,
|
|
109
|
+
:streams_durable_patterns
|
|
109
110
|
attr_reader :streams_default_broadcast_mode # rubocop:disable Style/AccessorGrouping
|
|
110
111
|
|
|
111
112
|
# AppSignal integration (auto-loaded when ::Appsignal is defined and this is true).
|
|
@@ -221,6 +222,7 @@ module Pgbus
|
|
|
221
222
|
@streams_default_broadcast_mode = :ephemeral
|
|
222
223
|
@streams_orphan_sweep_interval = 3600 # 1 hour
|
|
223
224
|
@streams_orphan_threshold = 86_400 # 24 hours
|
|
225
|
+
@streams_durable_patterns = []
|
|
224
226
|
|
|
225
227
|
# AppSignal: auto-on when the appsignal gem is loaded; probe runs in
|
|
226
228
|
# the same process, so the operator can disable it independently.
|
|
@@ -365,12 +367,24 @@ module Pgbus
|
|
|
365
367
|
raise ArgumentError, "streams_orphan_sweep_interval must be a positive number or nil to disable"
|
|
366
368
|
end
|
|
367
369
|
|
|
370
|
+
raise ArgumentError, "streams_durable_patterns must be an Array of strings/regex" unless streams_durable_patterns.is_a?(Array)
|
|
371
|
+
|
|
368
372
|
return if streams_orphan_threshold.nil?
|
|
369
373
|
return if streams_orphan_threshold.is_a?(Numeric) && streams_orphan_threshold.positive?
|
|
370
374
|
|
|
371
375
|
raise ArgumentError, "streams_orphan_threshold must be a positive number or nil to disable"
|
|
372
376
|
end
|
|
373
377
|
|
|
378
|
+
# Returns true if the given stream name should be durable based on
|
|
379
|
+
# `streams_durable_patterns` (exact string or Regexp match) or the
|
|
380
|
+
# `streams_default_broadcast_mode` fallback.
|
|
381
|
+
def stream_durable?(name)
|
|
382
|
+
patterns = streams_durable_patterns || []
|
|
383
|
+
return true if patterns.any? { |p| p.is_a?(Regexp) ? p.match?(name) : p == name }
|
|
384
|
+
|
|
385
|
+
streams_default_broadcast_mode == :durable
|
|
386
|
+
end
|
|
387
|
+
|
|
374
388
|
# Set the worker capsule list. Accepts:
|
|
375
389
|
#
|
|
376
390
|
# String — parsed via Pgbus::Configuration::CapsuleDSL into capsules
|
data/lib/pgbus/streams.rb
CHANGED
|
@@ -73,11 +73,15 @@ module Pgbus
|
|
|
73
73
|
# satisfies the predicate. The label travels with the broadcast
|
|
74
74
|
# through PGMQ; the predicate itself lives in-process on the
|
|
75
75
|
# subscriber side and is evaluated per-connection by the Dispatcher.
|
|
76
|
-
|
|
76
|
+
# Per-broadcast `durable:` overrides the stream-level default for a
|
|
77
|
+
# single broadcast. `nil` (the default) defers to the stream's own
|
|
78
|
+
# `durable?` setting; `true`/`false` flip the mode for this call only.
|
|
79
|
+
def broadcast(payload, visible_to: nil, durable: nil)
|
|
77
80
|
wrapped = { "html" => payload.to_s }
|
|
78
81
|
wrapped["visible_to"] = visible_to.to_s if visible_to
|
|
79
82
|
|
|
80
|
-
|
|
83
|
+
use_durable = durable.nil? ? @durable : durable
|
|
84
|
+
return broadcast_ephemeral(wrapped) unless use_durable
|
|
81
85
|
|
|
82
86
|
ensure_queue!
|
|
83
87
|
transaction = current_open_transaction
|
data/lib/pgbus/version.rb
CHANGED
data/lib/pgbus.rb
CHANGED
|
@@ -104,11 +104,16 @@ module Pgbus
|
|
|
104
104
|
# clears it. The cache key is the resolved name string, not the raw
|
|
105
105
|
# streamables, so `Pgbus.stream(@order)` and `Pgbus.stream(@order)`
|
|
106
106
|
# in the same process return the same instance.
|
|
107
|
-
|
|
107
|
+
# `durable:` defaults to `nil` so the configuration resolves the mode:
|
|
108
|
+
# `streams_durable_patterns` first (exact string or regex match), then
|
|
109
|
+
# `streams_default_broadcast_mode`. Pass `durable: true`/`false`
|
|
110
|
+
# explicitly to bypass the resolver for this Stream instance.
|
|
111
|
+
def stream(streamables, durable: nil)
|
|
108
112
|
name = Streams::Stream.name_from(streamables)
|
|
109
|
-
|
|
113
|
+
resolved = durable.nil? ? configuration.stream_durable?(name) : durable
|
|
114
|
+
cache_key = "#{name}:#{resolved ? "d" : "e"}"
|
|
110
115
|
@stream_cache ||= Concurrent::Map.new
|
|
111
|
-
@stream_cache.compute_if_absent(cache_key) { Streams::Stream.new(streamables, durable:
|
|
116
|
+
@stream_cache.compute_if_absent(cache_key) { Streams::Stream.new(streamables, durable: resolved) }
|
|
112
117
|
end
|
|
113
118
|
|
|
114
119
|
# Compose a short, pgbus-safe stream identifier from any mix of
|