jetstream_bridge 1.14.0 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 649a6258b0dce4c43433916df6bb2f9c5d41ba233f05ce66b935853b16637b64
4
- data.tar.gz: 942589e88710ac2da1651baa5cee79dbd2304db0fa15a12a8c9d911c8d05ef44
3
+ metadata.gz: e107d86ffe1dfa7ee9362c82a6f827ad5e5501d0c9eedff4b2da359c360465cc
4
+ data.tar.gz: 33e9522da1b3a13161858c46b125978a3760d5263996ff4a12ad4b7d5ab2a8cd
5
5
  SHA512:
6
- metadata.gz: 10540646b48b7d605f5f92915d4d8be5aed2f72578a151c3f2e4bc500a2908df4c216f1baa0dc128fddd502ca4f88ef73e6c27bb56ab9174573619a298893d4e
7
- data.tar.gz: 0debe41380866ee0253570f87b7a3f13dbdbdd3456cbc655815da586612d36155df1f169ba5f321f037b0031f50552f6e8d5e82b04f52f49b41f4e05eb1c1a40
6
+ metadata.gz: 4c276cc1a4c2bfa086b39051d60a8cae9b3668c70a556ffd08c6235bf2031f74649872ec265921604c36589b1fa4776cd74094ecc5977aad3c09abe4d989e8f7
7
+ data.tar.gz: 571d9ca427e2ea0f06a428ec197242bd437f54711fefbcfa23f13450a39ad7c70bc70720af8ccad2b4039579246e2d056daac9bd48b11ea232e0fbb1a4369adc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jetstream_bridge (1.14.0)
4
+ jetstream_bridge (2.0.0)
5
5
  activerecord (>= 6.0)
6
6
  activesupport (>= 6.0)
7
7
  nats-pure (~> 2.4)
@@ -142,6 +142,8 @@ GEM
142
142
  racc (~> 1.4)
143
143
  nokogiri (1.18.7-arm64-darwin)
144
144
  racc (~> 1.4)
145
+ nokogiri (1.18.7-x86_64-linux-gnu)
146
+ racc (~> 1.4)
145
147
  parallel (1.27.0)
146
148
  parser (3.3.9.0)
147
149
  ast (~> 2.4.1)
data/README.md CHANGED
@@ -23,7 +23,7 @@ Includes durable consumers, backpressure, retries, **DLQ**, optional **Inbox/Out
23
23
 
24
24
  ```ruby
25
25
  # Gemfile
26
- gem "jetstream_bridge"
26
+ gem "jetstream_bridge", "~> 2.0"
27
27
  ```
28
28
 
29
29
  ```bash
@@ -257,7 +257,7 @@ You may run a separate process to subscribe and triage messages that exceed `max
257
257
  ### Scaling
258
258
 
259
259
  * Run consumers in **separate processes/containers**
260
- * Scale consumers independently from web
260
+ * Scale consumers independently of web
261
261
  * Tune `batch_size`, `ack_wait`, `max_deliver`, and `backoff`
262
262
 
263
263
  ### Health check
@@ -22,7 +22,7 @@ module JetstreamBridge
22
22
  def initialize(durable_name:, batch_size: DEFAULT_BATCH_SIZE, &block)
23
23
  @handler = block
24
24
  @batch_size = batch_size
25
- @durable = durable_name
25
+ @durable = durable_name || JetstreamBridge.config.durable_name
26
26
  @jts = Connection.connect!
27
27
 
28
28
  ensure_destination!
@@ -11,7 +11,7 @@ module JetstreamBridge
11
11
  @nats_urls = ENV['NATS_URLS'] || ENV['NATS_URL'] || 'nats://localhost:4222'
12
12
  @env = ENV['NATS_ENV'] || 'development'
13
13
  @app_name = ENV['APP_NAME'] || 'app'
14
- @destination_app = ENV['DESTINATION_APP']
14
+ @destination_app = ENV.fetch('DESTINATION_APP', nil)
15
15
 
16
16
  @max_deliver = 5
17
17
  @ack_wait = '30s'
@@ -44,5 +44,9 @@ module JetstreamBridge
44
44
  def dlq_subject
45
45
  "#{env}.data.sync.dlq"
46
46
  end
47
+
48
+ def durable_name
49
+ "#{env}-#{app_name}-workers"
50
+ end
47
51
  end
48
52
  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: -> { !self.class.has_column?(:event_id) && self.class.has_column?(:resource_type) }
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: -> { !self.class.has_column?(:event_id) && self.class.has_column?(:resource_id) }
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 ||= 'pending' if self.class.has_column?(:status) && status.blank?
67
- self.enqueued_at ||= now if self.class.has_column?(:enqueued_at) && enqueued_at.blank?
68
- self.attempts = 0 if self.class.has_column?(:attempts) && attempts.nil?
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 JSON.parse(v) rescue {}
89
- when Hash then v
90
- else v.respond_to?(:as_json) ? v.as_json : {}
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) = 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
- 'Enable `use_outbox` only in apps with ActiveRecord, or add ' \
110
- '`gem "activerecord"` to your Gemfile.'
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
@@ -4,5 +4,5 @@
4
4
  #
5
5
  # Version constant for the gem.
6
6
  module JetstreamBridge
7
- VERSION = '1.14.0'
7
+ VERSION = '2.0.0'
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jetstream_bridge
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Attara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-19 00:00:00.000000000 Z
11
+ date: 2025-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord