pg_versions 2.0 → 2.1
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/lib/pg_versions/pg_versions.rb +29 -18
- data/lib/pg_versions/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6eab4d5b85196e9a17fe15efdb09cb6ef83d6821a060c40a5c68e3fae7c9fed
|
4
|
+
data.tar.gz: ff1c5c4157163144f7bb1808115c52e50438d8119415b7ea19df18e82e9d5bcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12c82c86f3138b9b27eaade5a3eb97779b246de26a680de3e23e6d99daa576cc56a1b04ce2c8b82b81f72f8402a73f5eb2e5e7d4babb57651d458317f40eeea5
|
7
|
+
data.tar.gz: 70c41180db0eff19a524f1b65165800c08a50a22ddf25f07daaacb58a0c0b901e0bbf22b620f61499f52788ec4d9120de373b2cdbb3a1aaae3d02481dc211bd3
|
@@ -81,6 +81,7 @@ module PgVersions
|
|
81
81
|
|
82
82
|
#TODO: ensure this is called only once per transaction, or that all bumps occur in the same order in all transactions, to avoid deadlocks
|
83
83
|
def self.bump(*channels, connection: nil)
|
84
|
+
#TODO: pg_connection.exec returned nil once during testing.
|
84
85
|
PgVersions.with_connection(connection) { |pg_connection|
|
85
86
|
channels = [channels].flatten.sort
|
86
87
|
return {} if channels.size == 0
|
@@ -107,7 +108,9 @@ module PgVersions
|
|
107
108
|
FROM
|
108
109
|
to_bump
|
109
110
|
JOIN updated ON to_bump.channel = updated.channel;
|
110
|
-
")
|
111
|
+
") { |result|
|
112
|
+
result.map { |row| [channels[Integer(row["i"])], string_to_version(row["version"])] }.to_h
|
113
|
+
}
|
111
114
|
}
|
112
115
|
end
|
113
116
|
|
@@ -130,8 +133,10 @@ module PgVersions
|
|
130
133
|
JOIN pg_versions ON pg_versions.channel = channels.channel
|
131
134
|
ORDER BY
|
132
135
|
i DESC;
|
133
|
-
")
|
134
|
-
|
136
|
+
") { |result|
|
137
|
+
result.each { |row|
|
138
|
+
versions[channels.delete_at(Integer(row["i"]))] = string_to_version(row["version"])
|
139
|
+
}
|
135
140
|
}
|
136
141
|
#TODO: bump in the same query instead of calling bump
|
137
142
|
versions.merge!(self.bump(channels, connection: pg_connection)) if channels.size > 0
|
@@ -186,7 +191,6 @@ module PgVersions
|
|
186
191
|
listen(pg_connection, channel)
|
187
192
|
}
|
188
193
|
read(pg_connection, @subscribers.keys).each_pair { |channel, version|
|
189
|
-
#p channel, version
|
190
194
|
@subscribers[channel].each { |subscriber|
|
191
195
|
subscriber.notify({ channel => version })
|
192
196
|
}
|
@@ -305,8 +309,8 @@ module PgVersions
|
|
305
309
|
end
|
306
310
|
|
307
311
|
|
308
|
-
def subscribe(*channels, known: {})
|
309
|
-
subscription = Subscription.new(@connection_thread)
|
312
|
+
def subscribe(*channels, known: {}, batch_delay: 0.01)
|
313
|
+
subscription = Subscription.new(@connection_thread, batch_delay)
|
310
314
|
subscription.subscribe([channels].flatten, known: known)
|
311
315
|
if block_given?
|
312
316
|
Thread.handle_interrupt(Object => :never) {
|
@@ -326,8 +330,9 @@ module PgVersions
|
|
326
330
|
|
327
331
|
class Subscription
|
328
332
|
|
329
|
-
def initialize(connection_thread)
|
333
|
+
def initialize(connection_thread, batch_delay)
|
330
334
|
@connection_thread = connection_thread
|
335
|
+
@batch_delay = batch_delay
|
331
336
|
@notifications = Queue.new
|
332
337
|
@already_known_versions = Hash.new { |h,k| h[k] = [] }
|
333
338
|
@channels = Hash.new(0)
|
@@ -375,17 +380,23 @@ module PgVersions
|
|
375
380
|
|
376
381
|
|
377
382
|
#TODO: make this resume-able after forced exception
|
378
|
-
def wait(new_already_known_versions = {})
|
383
|
+
def wait(new_already_known_versions = {}, batch_delay: nil)
|
384
|
+
batch_delay = @batch_delay if batch_delay.nil?
|
379
385
|
update_already_known_versions(new_already_known_versions)
|
380
386
|
loop {
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
387
|
+
events = [@notifications.shift]
|
388
|
+
sleep batch_delay if batch_delay
|
389
|
+
events << @notifications.shift while not @notifications.empty?
|
390
|
+
changed_versions = {}
|
391
|
+
events.each { |versions|
|
392
|
+
return nil if not versions #termination
|
393
|
+
versions.each { |channel, version|
|
394
|
+
if (@already_known_versions[channel] <=> version) == -1
|
395
|
+
@already_known_versions[channel] = version
|
396
|
+
changed_versions[channel] = version
|
397
|
+
end
|
398
|
+
}
|
399
|
+
}
|
389
400
|
if changed_versions.size > 0
|
390
401
|
return Notification.new(changed_versions, @already_known_versions.dup)
|
391
402
|
end
|
@@ -393,9 +404,9 @@ module PgVersions
|
|
393
404
|
end
|
394
405
|
|
395
406
|
|
396
|
-
def each(new_already_known_versions = {})
|
407
|
+
def each(new_already_known_versions = {}, batch_delay: nil)
|
397
408
|
update_already_known_versions(new_already_known_versions)
|
398
|
-
while notification = wait()
|
409
|
+
while notification = wait(batch_delay: batch_delay)
|
399
410
|
yield notification
|
400
411
|
end
|
401
412
|
end
|
data/lib/pg_versions/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_versions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '2.
|
4
|
+
version: '2.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yunta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|