wal 0.0.21 → 0.0.23

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: 302e387a9951a4120fea323ca2f3eee13e8608963defa796c8ce0193ac1f2310
4
- data.tar.gz: 7adfed0108d9e3671eb83f3750babe622acb1470cc85447a74ab8519c9e41122
3
+ metadata.gz: 3a7144e35e8bfe1df54e18fa1e4b9c94e4bb6926ed0de011e0e4006ce08c44cd
4
+ data.tar.gz: 21196f54b92390273288aac5fed7b5fdcd79842dda0d63cbb0cada583bca8cd3
5
5
  SHA512:
6
- metadata.gz: 06d389b77e47f82dbcf6c3397c0e5c9b7d9b9fba124273e58d2a336d45c341317cb17ce0810e84c5cebf10ce51b12a0b26102a1600fa84e79f09fc42cb9fd89e
7
- data.tar.gz: '09ccf267a08bf2007aeb799ca521445fe25fbaa55ddabf1618577ef70f91b0baaff1bf0f622800d7dd9e2d210c8eaf2f401fa8dc847f72f45c950a4d74d974ab'
6
+ metadata.gz: 88be295b55c90871dc4aa8731e21c03fff1b890e59a3b9ec000276c5d0b2dad96660b1686328af6e208084fc5389f90c8925dbc27fb29de56e535063eaf20899
7
+ data.tar.gz: a13bd85ed047f5b7bfcfe839bb0ff8643587ae6c6ca81ef4f56809a96e4daff6a6f7423c9eff3a715cfa72f27e84b99765f003b4d40b0eacabf0d73cc7311bbc
data/exe/wal CHANGED
@@ -91,7 +91,10 @@ elsif cli["start"]
91
91
  temporary = config["temporary"] || false
92
92
  publications = config["publications"] || []
93
93
  replicator_class = config["replicator"].presence&.constantize || Wal::Replicator
94
- retries = config["retries"]&.to_i || 5
94
+ max_retries = config["retries"]&.to_i || (2**32 - 1)
95
+ retries = 0
96
+ backoff = config["retry_backoff"]&.to_f || 1
97
+ backoff_expoent = config["retry_backoff_expoent"]&.to_f
95
98
 
96
99
  Thread.new(slot, watcher, temporary, publications) do |replication_slot, watcher, use_temporary_slot, publications|
97
100
  replication_slot = "#{replication_slot}_#{SecureRandom.alphanumeric(4)}" if use_temporary_slot
@@ -103,10 +106,13 @@ elsif cli["start"]
103
106
  begin
104
107
  replicator.replicate_forever(watcher, publications:)
105
108
  rescue StandardError => err
106
- if retries > 0
109
+ if retries < max_retries
107
110
  Wal.logger&.error("[#{replication_slot}] Error #{err}")
108
- retries -= 1
109
- sleep 2 ** retries
111
+ retries += 1
112
+ backoff_time = backoff_expoent ? (backoff * retries) ** backoff_expoent : backoff
113
+ puts "Restarting #{replication_slot} in #{backoff_time.floor(2)}s..."
114
+ sleep backoff_time
115
+ puts "Restarting #{replication_slot}"
110
116
  retry
111
117
  end
112
118
  raise
@@ -41,47 +41,46 @@ module Wal
41
41
 
42
42
  def self.inherited(subclass)
43
43
  super
44
- @@change_callbacks = Hash.new { |hash, key| hash[key] = [] }
45
- @@delete_callbacks = Hash.new { |hash, key| hash[key] = [] }
44
+ subclass.class_eval do
45
+ def self.change_callbacks
46
+ @change_callbacks ||= Hash.new { |hash, key| hash[key] = [] }
47
+ end
48
+
49
+ def self.delete_callbacks
50
+ @delete_callbacks ||= Hash.new { |hash, key| hash[key] = [] }
51
+ end
52
+ end
46
53
  end
47
54
 
48
55
  def self.on_insert(table, &block)
49
56
  table = table.is_a?(String) ? table : table.table_name
50
- @@change_callbacks[table].push(only: [:create], block: block)
57
+ change_callbacks[table].push(only: [:create], block: block)
51
58
  end
52
59
 
53
60
  def self.on_update(table, changed: nil, &block)
54
61
  table = table.is_a?(String) ? table : table.table_name
55
- @@change_callbacks[table].push(only: [:update], changed: changed&.map(&:to_s), block: block)
62
+ change_callbacks[table].push(only: [:update], changed: changed&.map(&:to_s), block: block)
56
63
  end
57
64
 
58
65
  def self.on_save(table, changed: nil, &block)
59
66
  table = table.is_a?(String) ? table : table.table_name
60
- @@change_callbacks[table].push(only: [:create, :update], changed: changed&.map(&:to_s), block: block)
67
+ change_callbacks[table].push(only: [:create, :update], changed: changed&.map(&:to_s), block: block)
61
68
  end
62
69
 
63
70
  def self.on_delete(table, &block)
64
71
  table = table.is_a?(String) ? table : table.table_name
65
- @@delete_callbacks[table].push(block: block)
66
- end
67
-
68
- def self.change_callbacks
69
- @@change_callbacks
70
- end
71
-
72
- def self.delete_callbacks
73
- @@delete_callbacks
72
+ delete_callbacks[table].push(block: block)
74
73
  end
75
74
 
76
75
  def on_record_changed(event)
77
76
  case event
78
77
  when InsertEvent
79
- @@change_callbacks[event.full_table_name]
78
+ self.class.change_callbacks[event.full_table_name]
80
79
  .filter { |callback| callback[:only].include? :create }
81
80
  .each { |callback| instance_exec(event, &callback[:block]) }
82
81
 
83
82
  when UpdateEvent
84
- @@change_callbacks[event.full_table_name]
83
+ self.class.change_callbacks[event.full_table_name]
85
84
  .filter { |callback| callback[:only].include? :update }
86
85
  .each do |callback|
87
86
  if (attributes = callback[:changed])
@@ -92,14 +91,14 @@ module Wal
92
91
  end
93
92
 
94
93
  when DeleteEvent
95
- @@delete_callbacks[event.full_table_name].each do |callback|
94
+ self.class.delete_callbacks[event.full_table_name].each do |callback|
96
95
  instance_exec(event, &callback[:block])
97
96
  end
98
97
  end
99
98
  end
100
99
 
101
100
  def should_watch_table?(table)
102
- (@@change_callbacks.keys | @@delete_callbacks.keys).include? table
101
+ (self.class.change_callbacks.keys | self.class.delete_callbacks.keys).include? table
103
102
  end
104
103
 
105
104
  # `RecordWatcher` supports three processing strategies:
@@ -155,6 +155,9 @@ module Wal
155
155
  else
156
156
  next
157
157
  end
158
+ rescue
159
+ watch_conn&.close
160
+ raise
158
161
  end
159
162
  end
160
163
 
data/lib/wal/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wal
4
- VERSION = "0.0.21"
4
+ VERSION = "0.0.23"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.21
4
+ version: 0.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Navarro
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-10-09 00:00:00.000000000 Z
10
+ date: 2025-10-29 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: pg