wal 0.0.24 → 0.0.25

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/exe/wal +45 -35
  3. data/lib/wal/version.rb +1 -1
  4. data/rbi/wal.rbi +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dbc63f98019737c35c19d3dab2f5d3d51018f00cc242489ce49fda0d9678b2e6
4
- data.tar.gz: 22f30e0b6e380a90fc898b279a4badc03fc04183c8d01df12ba8cf851844fb52
3
+ metadata.gz: 7ff2f0a5d9392268db27728b053f29ac897649314c72b857b0d43303bb8face1
4
+ data.tar.gz: a378a4d4c4e5f3f1e6d9a988fe61947683c52614223e27a67371b4042434a2cb
5
5
  SHA512:
6
- metadata.gz: 9c8a14e8cc979763892ffbfdf3e2988ca1f90fa3185b5a78e689c5149fc5eda74a2ef128530b6616f6a2f5559c6df3529334c45f0080728fca0776656d61570c
7
- data.tar.gz: ae98a50cffa3399d122012f15088274af73752aff7744481402d141e07e12b686294e7a004c61a799cade16f1cab2cf077fde1402124b3ec0760dd51ee62514f
6
+ metadata.gz: 5514c83c92062744f25cdc2f7f08aaa79cdbd4bc7cd49c6028de964f3d5c02a0a0b8d2d3b8f3a6cdf69954adb45f5a89866f5fdd193cebfd1cb1fc24049d3ba9
7
+ data.tar.gz: a29bb6e5c5cc9795e82d88d15f4e820cc88b651f58950c67120dc988454aa6230d0e85af25e016289402c5bb5a6b1db9341e039fdc350155a86710190be6bad2
data/exe/wal CHANGED
@@ -69,7 +69,7 @@ class Wal::LoggingReplicator
69
69
  end
70
70
  end
71
71
 
72
- if cli["watch"]
72
+ def watch(db_config, cli)
73
73
  watcher = cli["--watcher"].constantize.new
74
74
  use_temporary_slot = cli["--tmp-slot"] || false
75
75
  replication_slot = cli["--slot"]
@@ -82,46 +82,50 @@ if cli["watch"]
82
82
  replicator = Wal::LoggingReplicator.new(replication_slot, replicator)
83
83
  replicator.replicate_forever(watcher, publications:)
84
84
  puts "Watcher finished for #{replication_slot}"
85
+ end
85
86
 
86
- elsif cli["start"]
87
- slots = YAML.load_file(cli["<config-file>"])["slots"]
88
-
89
- workers = slots.map do |slot, config|
90
- watcher = config["watcher"].constantize.new
91
- temporary = config["temporary"] || false
92
- publications = config["publications"] || []
93
- replicator_class = config["replicator"].presence&.constantize || Wal::Replicator
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
98
-
99
- Thread.new(slot, watcher, temporary, publications) do |replication_slot, watcher, use_temporary_slot, publications|
100
- replication_slot = "#{replication_slot}_#{SecureRandom.alphanumeric(4)}" if use_temporary_slot
101
- puts "Watcher started for #{replication_slot} slot (#{publications.join(", ")})"
102
-
87
+ def start_worker(db_config, slot, config)
88
+ watcher = config["watcher"].constantize.new
89
+ temporary = config["temporary"] || false
90
+ publications = config["publications"] || []
91
+ replicator_class = config["replicator"].presence&.constantize || Wal::Replicator
92
+ max_retries = config["retries"]&.to_i || (2**32 - 1)
93
+ retries = 0
94
+ backoff = config["retry_backoff"]&.to_f || 1
95
+ backoff_expoent = config["retry_backoff_expoent"]&.to_f
96
+
97
+ Thread.new(slot, watcher, temporary, publications) do |replication_slot, watcher, use_temporary_slot, publications|
98
+ replication_slot = "#{replication_slot}_#{SecureRandom.alphanumeric(4)}" if use_temporary_slot
99
+ puts "Watcher started for #{replication_slot} slot (#{publications.join(", ")})"
100
+
101
+ begin
103
102
  replicator = replicator_class.new(replication_slot:, use_temporary_slot:, db_config:)
104
103
  replicator = Wal::LoggingReplicator.new(replication_slot, replicator)
105
-
106
- begin
107
- replicator.replicate_forever(watcher, publications:)
108
- rescue StandardError => err
109
- if retries < max_retries
110
- Wal.logger&.error("[#{replication_slot}] Error #{err}")
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}"
116
- retry
117
- end
118
- raise
104
+ replicator.replicate_forever(watcher, publications:)
105
+ rescue StandardError => err
106
+ if retries < max_retries
107
+ Wal.logger&.error("[#{replication_slot}] Error #{err}")
108
+ retries += 1
109
+ backoff_time = backoff_expoent ? (backoff * retries) ** backoff_expoent : backoff
110
+ puts "Restarting #{replication_slot} in #{backoff_time.floor(2)}s..."
111
+ sleep backoff_time
112
+ puts "Restarting #{replication_slot}"
113
+ retry
119
114
  end
115
+ raise
116
+ end
120
117
 
121
- puts "Watcher finished for #{replication_slot}"
118
+ puts "Watcher finished for #{replication_slot}"
122
119
 
123
- Process.kill("TERM", Process.pid)
124
- end
120
+ Process.kill("TERM", Process.pid)
121
+ end
122
+ end
123
+
124
+ def start(db_config, cli)
125
+ slots = YAML.load_file(cli["<config-file>"])["slots"]
126
+
127
+ workers = slots.map do |slot, config|
128
+ start_worker(db_config, slot, config)
125
129
  end
126
130
 
127
131
  ping = Thread.new do
@@ -147,3 +151,9 @@ elsif cli["start"]
147
151
 
148
152
  workers.each(&:join)
149
153
  end
154
+
155
+ if cli["watch"]
156
+ watch(db_config, cli)
157
+ elsif cli["start"]
158
+ start(db_config, cli)
159
+ end
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.24"
4
+ VERSION = "0.0.25"
5
5
  end
data/rbi/wal.rbi CHANGED
@@ -7,7 +7,7 @@ module Wal
7
7
  UpdateEvent,
8
8
  DeleteEvent,
9
9
  ) }
10
- VERSION = "0.0.24"
10
+ VERSION = "0.0.25"
11
11
 
12
12
  class << self
13
13
  sig { returns(T.class_of(Logger)) }
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.24
4
+ version: 0.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Navarro
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2026-01-02 00:00:00.000000000 Z
10
+ date: 2026-01-12 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: pg