message_bus 5.0.0 → 5.1.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/CHANGELOG +7 -0
- data/lib/message_bus/backends/base.rb +2 -1
- data/lib/message_bus/backends/memory.rb +9 -4
- data/lib/message_bus/backends/postgres.rb +10 -4
- data/lib/message_bus/backends/redis.rb +8 -2
- data/lib/message_bus/version.rb +1 -1
- data/spec/lib/message_bus/backend_spec.rb +26 -0
- 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: 52492917d068eb8e797c93a776b0a7496f430bad3bf0fe79c5b1e192091cb18d
|
|
4
|
+
data.tar.gz: da51e98e5f18e67a4de7769b43cf039eada80a5314af9552635e9e4934167c2d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b59e2edf77537c7c8d5d55903517a37378f041dfbf4cb0f63e4dc6f2ab51c744395527c34b8152ac9f82b6435390edb84fc91816980698bc58210bc5d0a138b4
|
|
7
|
+
data.tar.gz: e750096d991a99db95d4e447e6c5f22f023df1155ef38b5517ab5aa23488fd2f5c87dce04153b8246ff439690385e819cfd3e052ef9181030815b78b95054e23
|
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
19-11-2026
|
|
2
|
+
|
|
3
|
+
- Version 5.1.0
|
|
4
|
+
|
|
5
|
+
- FEATURE: `expire_all_backlogs!` accepts an optional `site_id:` to expire the backlogs of a single site
|
|
6
|
+
- FIX: `expire_all_backlogs!` on the Redis backend now expires per-channel backlogs, not only the global backlog
|
|
7
|
+
|
|
1
8
|
04-09-2026
|
|
2
9
|
|
|
3
10
|
- Version 5.0.0
|
|
@@ -89,8 +89,9 @@ module MessageBus
|
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
# Deletes all backlogs and their data. Does not delete non-backlog data that message_bus may persist, depending on the concrete backend implementation. Use with extreme caution.
|
|
92
|
+
# @param [String] site_id if given, only the backlogs of that site's channels are deleted
|
|
92
93
|
# @abstract
|
|
93
|
-
def expire_all_backlogs!
|
|
94
|
+
def expire_all_backlogs!(site_id: nil)
|
|
94
95
|
raise ConcreteClassMustImplementError
|
|
95
96
|
end
|
|
96
97
|
|
|
@@ -130,9 +130,14 @@ module MessageBus
|
|
|
130
130
|
end
|
|
131
131
|
|
|
132
132
|
# use with extreme care, will nuke all of the data
|
|
133
|
-
def expire_all_backlogs!
|
|
133
|
+
def expire_all_backlogs!(site_id: nil)
|
|
134
134
|
sync do
|
|
135
|
-
|
|
135
|
+
if site_id
|
|
136
|
+
site_suffix = "#{MessageBus::Implementation::ENCODE_SITE_TOKEN}#{site_id}"
|
|
137
|
+
@channels.delete_if { |name, _| name.end_with?(site_suffix) }
|
|
138
|
+
else
|
|
139
|
+
@channels = {}
|
|
140
|
+
end
|
|
136
141
|
end
|
|
137
142
|
end
|
|
138
143
|
|
|
@@ -219,8 +224,8 @@ module MessageBus
|
|
|
219
224
|
end
|
|
220
225
|
|
|
221
226
|
# (see Base#expire_all_backlogs!)
|
|
222
|
-
def expire_all_backlogs!
|
|
223
|
-
client.expire_all_backlogs!
|
|
227
|
+
def expire_all_backlogs!(site_id: nil)
|
|
228
|
+
client.expire_all_backlogs!(site_id: site_id)
|
|
224
229
|
end
|
|
225
230
|
|
|
226
231
|
# (see Base#publish)
|
|
@@ -117,8 +117,13 @@ module MessageBus
|
|
|
117
117
|
end
|
|
118
118
|
|
|
119
119
|
# use with extreme care, will nuke all of the data
|
|
120
|
-
def expire_all_backlogs!
|
|
121
|
-
|
|
120
|
+
def expire_all_backlogs!(site_id: nil)
|
|
121
|
+
if site_id
|
|
122
|
+
hold { |conn| exec_prepared(conn, 'expire_site_backlogs', ["#{MessageBus::Implementation::ENCODE_SITE_TOKEN}#{site_id}"]) }
|
|
123
|
+
nil
|
|
124
|
+
else
|
|
125
|
+
reset!
|
|
126
|
+
end
|
|
122
127
|
end
|
|
123
128
|
|
|
124
129
|
def max_id(channel = nil)
|
|
@@ -269,6 +274,7 @@ module MessageBus
|
|
|
269
274
|
conn.exec 'PREPARE channel_backlog AS SELECT id, value FROM message_bus WHERE ((channel = $1) AND (id > $2)) ORDER BY id'
|
|
270
275
|
conn.exec 'PREPARE global_backlog AS SELECT id, channel, value FROM message_bus WHERE (id > $1) ORDER BY id'
|
|
271
276
|
conn.exec "PREPARE expire AS DELETE FROM message_bus WHERE added_at < CURRENT_TIMESTAMP - ($1::text || ' seconds')::interval"
|
|
277
|
+
conn.exec 'PREPARE expire_site_backlogs AS DELETE FROM message_bus WHERE right(channel, length($1)) = $1'
|
|
272
278
|
conn.exec 'PREPARE get_message AS SELECT value FROM message_bus WHERE ((channel = $1) AND (id = $2))'
|
|
273
279
|
conn.exec 'PREPARE max_channel_id AS SELECT max(id) FROM message_bus WHERE (channel = $1)'
|
|
274
280
|
conn.exec 'PREPARE max_channel_ids AS SELECT channel, max(id) FROM message_bus WHERE (channel = ANY($1)) GROUP BY channel'
|
|
@@ -324,8 +330,8 @@ module MessageBus
|
|
|
324
330
|
end
|
|
325
331
|
|
|
326
332
|
# (see Base#expire_all_backlogs!)
|
|
327
|
-
def expire_all_backlogs!
|
|
328
|
-
client.expire_all_backlogs!
|
|
333
|
+
def expire_all_backlogs!(site_id: nil)
|
|
334
|
+
client.expire_all_backlogs!(site_id: site_id)
|
|
329
335
|
end
|
|
330
336
|
|
|
331
337
|
# (see Base#publish)
|
|
@@ -83,8 +83,10 @@ module MessageBus
|
|
|
83
83
|
|
|
84
84
|
# Deletes all backlogs and their data. Does not delete ID pointers, so new publications will get IDs that continue from the last publication before the expiry. Use with extreme caution.
|
|
85
85
|
# @see Base#expire_all_backlogs!
|
|
86
|
-
def expire_all_backlogs!
|
|
87
|
-
|
|
86
|
+
def expire_all_backlogs!(site_id: nil)
|
|
87
|
+
site_suffix = escape_glob("#{MessageBus::Implementation::ENCODE_SITE_TOKEN}#{site_id}") if site_id
|
|
88
|
+
pub_redis.scan_each(match: "#{backlog_key("*")}#{site_suffix}") { |k| pub_redis.del k }
|
|
89
|
+
pub_redis.del(global_backlog_key) if !site_id
|
|
88
90
|
end
|
|
89
91
|
|
|
90
92
|
# Note, the script takes care of all expiry of keys, however
|
|
@@ -359,6 +361,10 @@ LUA
|
|
|
359
361
|
"_message_bus_#{db}"
|
|
360
362
|
end
|
|
361
363
|
|
|
364
|
+
def escape_glob(str)
|
|
365
|
+
str.gsub(/[*?\[\]\\]/) { |c| "\\#{c}" }
|
|
366
|
+
end
|
|
367
|
+
|
|
362
368
|
def backlog_key(channel)
|
|
363
369
|
"__mb_backlog_n_#{channel}"
|
|
364
370
|
end
|
data/lib/message_bus/version.rb
CHANGED
|
@@ -33,6 +33,32 @@ describe BACKEND_CLASS do
|
|
|
33
33
|
]
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
+
it "can expire all backlogs" do
|
|
37
|
+
@bus.publish "/foo", "aa"
|
|
38
|
+
@bus.publish "/foo$|$one", "bb"
|
|
39
|
+
|
|
40
|
+
@bus.expire_all_backlogs!
|
|
41
|
+
|
|
42
|
+
@bus.backlog("/foo", 0).to_a.must_equal []
|
|
43
|
+
@bus.backlog("/foo$|$one", 0).to_a.must_equal []
|
|
44
|
+
@bus.global_backlog(0).to_a.must_equal []
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "can expire the backlogs of a single site" do
|
|
48
|
+
@bus.publish "/foo$|$one", "aa"
|
|
49
|
+
@bus.publish "/foo$|$two", "bb"
|
|
50
|
+
@bus.publish "/foo$|$*", "cc"
|
|
51
|
+
@bus.publish "/foo", "dd"
|
|
52
|
+
|
|
53
|
+
@bus.expire_all_backlogs!(site_id: "one")
|
|
54
|
+
@bus.expire_all_backlogs!(site_id: "t*")
|
|
55
|
+
|
|
56
|
+
@bus.backlog("/foo$|$one", 0).to_a.must_equal []
|
|
57
|
+
@bus.backlog("/foo$|$two", 0).map(&:data).must_equal ["bb"]
|
|
58
|
+
@bus.backlog("/foo$|$*", 0).map(&:data).must_equal ["cc"]
|
|
59
|
+
@bus.backlog("/foo", 0).map(&:data).must_equal ["dd"]
|
|
60
|
+
end
|
|
61
|
+
|
|
36
62
|
it "should initialize with max_backlog_size" do
|
|
37
63
|
BACKEND_CLASS.new({}, 2000).max_backlog_size.must_equal 2000
|
|
38
64
|
end
|