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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9e7369bd90c71a1c25bc9fdafe8905d8cdca99e5ae1deffb9c7b304aecc881d
4
- data.tar.gz: 44d3fb5bf94742541ba5f9474c06cc602b2a7490decb7daee846c4b8f5ce1bbe
3
+ metadata.gz: 3dea01adf92fdfda132e0ce03189733ca9d3e4a60e26517abe81d53d64b02b19
4
+ data.tar.gz: f539018648e02a5ea4753e058a3fe383b26d7f09a00d53124489eb640e1a2cf8
5
5
  SHA512:
6
- metadata.gz: be5efa4a81ec3244475bdbbda0dd90aad02076f422ffc0f6def444e5a0553a875a414a3f98049dff7a3471700515168ac7cab1e4394d379d8a316cea4d1981e4
7
- data.tar.gz: 515bf628c80f44252579432eb34d27c3f14fb830a7be0e479ca98b5d5651823c5dfb044276d44e9624e122accfab1faf93479827fcf92a5cacc75ef300a534f7
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pgbus
4
- VERSION = "0.6.1"
4
+ VERSION = "0.6.2"
5
5
  end
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.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson