jetstream_bridge 1.13.0 → 1.15.0
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/Gemfile.lock +1 -1
- data/lib/jetstream_bridge/inbox_event.rb +21 -10
- data/lib/jetstream_bridge/outbox_event.rb +26 -12
- data/lib/jetstream_bridge/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: 52de97c8d390176c6113c836f07126258f513ddf7feac51dd570d271a43f8ca5
|
4
|
+
data.tar.gz: 56a583ab2be2170e28afe5e1c89b33e51f8d40fa84dfb66b89666949e9390dc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64408358299860a7bb08897d8e0360e265274990499fe963cbd133a4592e186d71055814d9aeaf87b695b8035fab095a6f67ef99027135f9c7a5205e299be11e
|
7
|
+
data.tar.gz: 0bff44a878e9a78f8288c6aed2f9dd8319a249b8f6b1f3275666040f248999a5cfda73fbc5196f6641a84f52ffcad0eba001bc0ac71ab83e6b04c0ce21b8d8f2
|
data/Gemfile.lock
CHANGED
@@ -15,6 +15,7 @@ module JetstreamBridge
|
|
15
15
|
# Safe column presence check that never boots a connection during class load.
|
16
16
|
def has_column?(name)
|
17
17
|
return false unless ar_connected?
|
18
|
+
|
18
19
|
connection.schema_cache.columns_hash(table_name).key?(name.to_s)
|
19
20
|
rescue ActiveRecord::ConnectionNotEstablished, ActiveRecord::NoDatabaseError
|
20
21
|
false
|
@@ -22,7 +23,7 @@ module JetstreamBridge
|
|
22
23
|
|
23
24
|
def ar_connected?
|
24
25
|
ActiveRecord::Base.connected? && connection_pool.active_connection?
|
25
|
-
rescue
|
26
|
+
rescue StandardError
|
26
27
|
false
|
27
28
|
end
|
28
29
|
end
|
@@ -42,7 +43,7 @@ module JetstreamBridge
|
|
42
43
|
|
43
44
|
validates :stream_seq,
|
44
45
|
uniqueness: { scope: :stream },
|
45
|
-
if:
|
46
|
+
if: lambda {
|
46
47
|
!self.class.has_column?(:event_id) &&
|
47
48
|
self.class.has_column?(:stream_seq) &&
|
48
49
|
self.class.has_column?(:stream)
|
@@ -50,7 +51,7 @@ module JetstreamBridge
|
|
50
51
|
|
51
52
|
validates :stream_seq,
|
52
53
|
uniqueness: true,
|
53
|
-
if:
|
54
|
+
if: lambda {
|
54
55
|
!self.class.has_column?(:event_id) &&
|
55
56
|
self.class.has_column?(:stream_seq) &&
|
56
57
|
!self.class.has_column?(:stream)
|
@@ -62,8 +63,10 @@ module JetstreamBridge
|
|
62
63
|
|
63
64
|
# ---- Defaults that do not require schema at load time ----
|
64
65
|
before_validation do
|
65
|
-
self.status
|
66
|
-
|
66
|
+
self.status ||= 'received' if self.class.has_column?(:status) && status.blank?
|
67
|
+
if self.class.has_column?(:received_at) && received_at.blank?
|
68
|
+
self.received_at ||= Time.now.utc
|
69
|
+
end
|
67
70
|
end
|
68
71
|
|
69
72
|
# ---- Helpers ----
|
@@ -80,8 +83,12 @@ module JetstreamBridge
|
|
80
83
|
def payload_hash
|
81
84
|
v = self[:payload]
|
82
85
|
case v
|
83
|
-
when String then
|
84
|
-
|
86
|
+
when String then begin
|
87
|
+
JSON.parse(v)
|
88
|
+
rescue StandardError
|
89
|
+
{}
|
90
|
+
end
|
91
|
+
when Hash then v
|
85
92
|
else v.respond_to?(:as_json) ? v.as_json : {}
|
86
93
|
end
|
87
94
|
end
|
@@ -93,14 +100,18 @@ module JetstreamBridge
|
|
93
100
|
def method_missing(method_name, *_args, &_block)
|
94
101
|
raise_missing_ar!('Inbox', method_name)
|
95
102
|
end
|
96
|
-
|
103
|
+
|
104
|
+
def respond_to_missing?(_m, _p = false)
|
105
|
+
false
|
106
|
+
end
|
97
107
|
|
98
108
|
private
|
109
|
+
|
99
110
|
def raise_missing_ar!(which, method_name)
|
100
111
|
raise(
|
101
112
|
"#{which} requires ActiveRecord (tried to call ##{method_name}). " \
|
102
|
-
|
103
|
-
|
113
|
+
'Enable `use_inbox` only in apps with ActiveRecord, or add ' \
|
114
|
+
'`gem \"activerecord\"` to your Gemfile.'
|
104
115
|
)
|
105
116
|
end
|
106
117
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'json'
|
4
|
+
|
3
5
|
begin
|
4
6
|
require 'active_record'
|
5
7
|
rescue LoadError
|
@@ -15,6 +17,7 @@ module JetstreamBridge
|
|
15
17
|
# Safe column presence check that never boots a connection during class load.
|
16
18
|
def has_column?(name)
|
17
19
|
return false unless ar_connected?
|
20
|
+
|
18
21
|
connection.schema_cache.columns_hash(table_name).key?(name.to_s)
|
19
22
|
rescue ActiveRecord::ConnectionNotEstablished, ActiveRecord::NoDatabaseError
|
20
23
|
false
|
@@ -23,7 +26,7 @@ module JetstreamBridge
|
|
23
26
|
def ar_connected?
|
24
27
|
# Avoid creating a connection; rescue if pool isn't set yet.
|
25
28
|
ActiveRecord::Base.connected? && connection_pool.active_connection?
|
26
|
-
rescue
|
29
|
+
rescue StandardError
|
27
30
|
false
|
28
31
|
end
|
29
32
|
end
|
@@ -42,11 +45,15 @@ module JetstreamBridge
|
|
42
45
|
# Fallback legacy fields when event_id is absent
|
43
46
|
validates :resource_type,
|
44
47
|
presence: true,
|
45
|
-
if:
|
48
|
+
if: lambda {
|
49
|
+
!self.class.has_column?(:event_id) && self.class.has_column?(:resource_type)
|
50
|
+
}
|
46
51
|
|
47
52
|
validates :resource_id,
|
48
53
|
presence: true,
|
49
|
-
if:
|
54
|
+
if: lambda {
|
55
|
+
!self.class.has_column?(:event_id) && self.class.has_column?(:resource_id)
|
56
|
+
}
|
50
57
|
|
51
58
|
validates :event_type,
|
52
59
|
presence: true,
|
@@ -63,9 +70,9 @@ module JetstreamBridge
|
|
63
70
|
# ---- Defaults that do not require schema at load time ----
|
64
71
|
before_validation do
|
65
72
|
now = Time.now.utc
|
66
|
-
self.status
|
67
|
-
self.enqueued_at ||= now
|
68
|
-
self.attempts
|
73
|
+
self.status ||= 'pending' if self.class.has_column?(:status) && status.blank?
|
74
|
+
self.enqueued_at ||= now if self.class.has_column?(:enqueued_at) && enqueued_at.blank?
|
75
|
+
self.attempts = 0 if self.class.has_column?(:attempts) && attempts.nil?
|
69
76
|
end
|
70
77
|
|
71
78
|
# ---- Helpers ----
|
@@ -85,9 +92,14 @@ module JetstreamBridge
|
|
85
92
|
def payload_hash
|
86
93
|
v = self[:payload]
|
87
94
|
case v
|
88
|
-
when String then
|
89
|
-
|
90
|
-
|
95
|
+
when String then begin
|
96
|
+
JSON.parse(v)
|
97
|
+
rescue StandardError
|
98
|
+
{}
|
99
|
+
end
|
100
|
+
when Hash then v
|
101
|
+
else
|
102
|
+
v.respond_to?(:as_json) ? v.as_json : {}
|
91
103
|
end
|
92
104
|
end
|
93
105
|
end
|
@@ -99,15 +111,17 @@ module JetstreamBridge
|
|
99
111
|
raise_missing_ar!('Outbox', method_name)
|
100
112
|
end
|
101
113
|
|
102
|
-
def respond_to_missing?(_m, _p = false)
|
114
|
+
def respond_to_missing?(_m, _p = false)
|
115
|
+
false
|
116
|
+
end
|
103
117
|
|
104
118
|
private
|
105
119
|
|
106
120
|
def raise_missing_ar!(which, method_name)
|
107
121
|
raise(
|
108
122
|
"#{which} requires ActiveRecord (tried to call ##{method_name}). " \
|
109
|
-
|
110
|
-
|
123
|
+
'Enable `use_outbox` only in apps with ActiveRecord, or add ' \
|
124
|
+
'`gem "activerecord"` to your Gemfile.'
|
111
125
|
)
|
112
126
|
end
|
113
127
|
end
|