pgbus 0.6.1 → 0.6.2
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/read_after.rb +40 -0
- data/lib/pgbus/version.rb +1 -1
- 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: 3dea01adf92fdfda132e0ce03189733ca9d3e4a60e26517abe81d53d64b02b19
|
|
4
|
+
data.tar.gz: f539018648e02a5ea4753e058a3fe383b26d7f09a00d53124489eb640e1a2cf8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a125013c9c84b87a276f7dce8a6bb3c5c1df7c5299dd34c9addcca030da0d2983dab7c61e0576eed4de813b25fc841a632a74baaaa05a0239d758bc651f9bdcc
|
|
7
|
+
data.tar.gz: 2610ca4fb946d381ed594fb56479c7ceb56d6dc46b2f492ce6bc0a3e966af6647ddb83a3dfb679bf4dc4d6e0e152362464f6a62706f4d4e6b29646be6f4af6f7
|
|
@@ -24,6 +24,10 @@ module Pgbus
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
rows.map { |row| build_envelope(row) }
|
|
27
|
+
rescue StandardError => e
|
|
28
|
+
raise unless missing_stream_queue?(e, sanitized)
|
|
29
|
+
|
|
30
|
+
[]
|
|
27
31
|
end
|
|
28
32
|
|
|
29
33
|
def stream_current_msg_id(stream_name)
|
|
@@ -34,6 +38,10 @@ module Pgbus
|
|
|
34
38
|
conn.exec(sql).first.fetch("max").to_i
|
|
35
39
|
end
|
|
36
40
|
end
|
|
41
|
+
rescue StandardError => e
|
|
42
|
+
raise unless missing_stream_queue?(e, sanitized)
|
|
43
|
+
|
|
44
|
+
0
|
|
37
45
|
end
|
|
38
46
|
|
|
39
47
|
def stream_oldest_msg_id(stream_name)
|
|
@@ -50,10 +58,42 @@ module Pgbus
|
|
|
50
58
|
value&.to_i
|
|
51
59
|
end
|
|
52
60
|
end
|
|
61
|
+
rescue StandardError => e
|
|
62
|
+
raise unless missing_stream_queue?(e, sanitized)
|
|
63
|
+
|
|
64
|
+
nil
|
|
53
65
|
end
|
|
54
66
|
|
|
55
67
|
private
|
|
56
68
|
|
|
69
|
+
# True if +error+ is a PG::UndefinedTable (or an
|
|
70
|
+
# ActiveRecord::StatementInvalid wrapping one) complaining about
|
|
71
|
+
# the stream's own PGMQ queue table (pgmq.q_<sanitized> or
|
|
72
|
+
# pgmq.a_<sanitized>).
|
|
73
|
+
#
|
|
74
|
+
# The stream-watermark and replay SQL above run on every page render
|
|
75
|
+
# for streams like `pgbus_stream_from Current.user`, but the queue
|
|
76
|
+
# table is only created on the FIRST broadcast via
|
|
77
|
+
# `ensure_stream_queue`. On a fresh database the very first page
|
|
78
|
+
# render therefore reads from a table that doesn't exist yet —
|
|
79
|
+
# semantically, "no queue" means "no messages" and must translate
|
|
80
|
+
# to a 0 watermark / empty replay rather than an exception. Any
|
|
81
|
+
# OTHER UndefinedTable (wrong schema, typo, operator error) still
|
|
82
|
+
# propagates so real bugs don't get swallowed.
|
|
83
|
+
#
|
|
84
|
+
# See issue #101.
|
|
85
|
+
def missing_stream_queue?(error, sanitized)
|
|
86
|
+
pg_error = pg_undefined_table?(error) ? error : error.cause
|
|
87
|
+
return false unless pg_undefined_table?(pg_error)
|
|
88
|
+
|
|
89
|
+
message = pg_error.message.to_s
|
|
90
|
+
message.include?("pgmq.q_#{sanitized}") || message.include?("pgmq.a_#{sanitized}")
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def pg_undefined_table?(error)
|
|
94
|
+
defined?(::PG::UndefinedTable) && error.is_a?(::PG::UndefinedTable)
|
|
95
|
+
end
|
|
96
|
+
|
|
57
97
|
# Builds the union of live and archive tables. The outer ORDER BY + LIMIT
|
|
58
98
|
# ensures we never return more than `limit` rows total even if both
|
|
59
99
|
# subqueries hit it. The 'live'/'archive' constants are how the streamer
|
data/lib/pgbus/version.rb
CHANGED