message_bus 4.3.6 → 4.3.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4df966b88978a23a9caeb38eec64b374d66ce1e364c419d1ac04c722dba36a7
4
- data.tar.gz: 7bb707ad44b5fb96d8682ed25993d535700a1f8617e3af70ead34c5514b842dc
3
+ metadata.gz: 8919c0fad186b16833bee6f60c2cbab838be989395dbb63d5ea83ea25770a817
4
+ data.tar.gz: 12223e8d6cb7c4ef043ea4bfed14e0993a0d826380c4a3f5d8faed4fa55bfc1a
5
5
  SHA512:
6
- metadata.gz: 600284061dbb261638b47f69535ddf937eaea43038bfce18495be6bcaa7550b9ce910bb32221ed8773e62a855b4adcc829131d9f74f0115d4777d25d451bf11f
7
- data.tar.gz: 2ec82be8cf27b4eca3da26e7d122a9a7640d8294ffe2212a3f13c0995238276c3ef5519c03869bbb8ce584651d91620bcf464c56ca5017eaf239237a70deee2b
6
+ metadata.gz: ecc907090650eb544f36dee2f1ffac2e5e27408ff570d91d104ba118f20c03d9815dc441e08929128d60bb54640e929ea1ca0123bf9790f9caf562e6860441ee
7
+ data.tar.gz: a899cf220f0838916462e97146d50c0a297237c0f0569abf92da8d401a02f5a303ef769cb3318e33c4ffcef99092b01845bb6070c9b4282eb8c0cd08de37091e
data/CHANGELOG CHANGED
@@ -1,5 +1,16 @@
1
+ 14-09-2023
2
+
3
+ - Version 4.3.8
4
+
5
+ - FIX: Typo in `group_ids_lookup` option name in Redis params exclusion list that was preventing the use of the redis backend along with this option.
6
+ - FIX: Removes close_db_connection! deprecation warning.
7
+
1
8
  28-06-2023
2
9
 
10
+ - Version 4.3.7
11
+
12
+ - FIX: Allow using `:long_polling_interval` with Redis gem version 5+.
13
+
3
14
  - Version 4.3.6
4
15
 
5
16
  - Don't error when trying to write a message to a closed client take 2
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'redis'
4
- require 'digest'
3
+ require "redis"
4
+ require "digest"
5
5
 
6
6
  module MessageBus
7
7
  module Backends
@@ -49,9 +49,7 @@ module MessageBus
49
49
  @redis_config = redis_config.dup
50
50
  @clear_every = redis_config.delete(:clear_every) || 1
51
51
  @logger = @redis_config[:logger]
52
- unless @redis_config[:enable_redis_logger]
53
- @redis_config[:logger] = nil
54
- end
52
+ @redis_config[:logger] = nil unless @redis_config[:enable_redis_logger]
55
53
  @max_backlog_size = max_backlog_size
56
54
  @max_global_backlog_size = 2000
57
55
  @max_in_memory_publish_backlog = 1000
@@ -61,7 +59,7 @@ module MessageBus
61
59
  @pub_redis = nil
62
60
  @subscribed = false
63
61
  # after 7 days inactive backlogs will be removed
64
- @max_backlog_age = 604800
62
+ @max_backlog_age = 604_800
65
63
  end
66
64
 
67
65
  # Reconnects to Redis; used after a process fork, typically triggered by a forking webserver
@@ -72,9 +70,7 @@ module MessageBus
72
70
 
73
71
  # (see Base#reset!)
74
72
  def reset!
75
- pub_redis.keys("__mb_*").each do |k|
76
- pub_redis.del k
77
- end
73
+ pub_redis.keys("__mb_*").each { |k| pub_redis.del k }
78
74
  end
79
75
 
80
76
  # (see Base#destroy)
@@ -85,9 +81,7 @@ module MessageBus
85
81
  # 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.
86
82
  # @see Base#expire_all_backlogs!
87
83
  def expire_all_backlogs!
88
- pub_redis.keys("__mb_*backlog_n").each do |k|
89
- pub_redis.del k
90
- end
84
+ pub_redis.keys("__mb_*backlog_n").each { |k| pub_redis.del k }
91
85
  end
92
86
 
93
87
  # Note, the script takes care of all expiry of keys, however
@@ -157,15 +151,15 @@ LUA
157
151
  max_backlog_size,
158
152
  max_global_backlog_size,
159
153
  channel,
160
- clear_every
154
+ clear_every,
161
155
  ],
162
156
  keys: [
163
157
  global_id_key,
164
158
  backlog_id_key,
165
159
  backlog_key,
166
160
  global_backlog_key,
167
- redis_channel_name
168
- ]
161
+ redis_channel_name,
162
+ ],
169
163
  )
170
164
  rescue ::Redis::CommandError => e
171
165
  if queue_in_memory && e.message =~ /READONLY/
@@ -173,7 +167,9 @@ LUA
173
167
  @in_memory_backlog << [channel, data]
174
168
  if @in_memory_backlog.length > @max_in_memory_publish_backlog
175
169
  @in_memory_backlog.delete_at(0)
176
- @logger.warn("Dropping old message cause max_in_memory_publish_backlog is full: #{e.message}\n#{e.backtrace.join('\n')}")
170
+ @logger.warn(
171
+ "Dropping old message cause max_in_memory_publish_backlog is full: #{e.message}\n#{e.backtrace.join('\n')}",
172
+ )
177
173
  end
178
174
  end
179
175
 
@@ -209,9 +205,7 @@ LUA
209
205
  backlog_key = backlog_key(channel)
210
206
  items = redis.zrangebyscore backlog_key, last_id.to_i + 1, "+inf"
211
207
 
212
- items.map do |i|
213
- MessageBus::Message.decode(i)
214
- end
208
+ items.map { |i| MessageBus::Message.decode(i) }
215
209
  end
216
210
 
217
211
  # (see Base#global_backlog)
@@ -254,13 +248,9 @@ LUA
254
248
  # we are subscribing on global and global is always going to be bigger than local
255
249
  # so worst case is a replay of a few messages
256
250
  message = get_message(channel, last_id)
257
- if message
258
- last_id = message.global_id
259
- end
260
- end
261
- global_subscribe(last_id) do |m|
262
- yield m if m.channel == channel
251
+ last_id = message.global_id if message
263
252
  end
253
+ global_subscribe(last_id) { |m| yield m if m.channel == channel }
264
254
  end
265
255
 
266
256
  # (see Base#global_unsubscribe)
@@ -280,36 +270,31 @@ LUA
280
270
 
281
271
  highest_id = last_id
282
272
 
283
- clear_backlog = lambda do
284
- retries = 4
285
- begin
286
- highest_id = process_global_backlog(highest_id, retries > 0, &blk)
287
- rescue BackLogOutOfOrder => e
288
- highest_id = e.highest_id
289
- retries -= 1
290
- sleep(rand(50) / 1000.0)
291
- retry
273
+ clear_backlog =
274
+ lambda do
275
+ retries = 4
276
+ begin
277
+ highest_id = process_global_backlog(highest_id, retries > 0, &blk)
278
+ rescue BackLogOutOfOrder => e
279
+ highest_id = e.highest_id
280
+ retries -= 1
281
+ sleep(rand(50) / 1000.0)
282
+ retry
283
+ end
292
284
  end
293
- end
294
285
 
295
286
  begin
296
287
  global_redis = new_redis_connection
297
288
 
298
- if highest_id
299
- clear_backlog.call(&blk)
300
- end
289
+ clear_backlog.call(&blk) if highest_id
301
290
 
302
291
  global_redis.subscribe(redis_channel_name) do |on|
303
292
  on.subscribe do
304
- if highest_id
305
- clear_backlog.call(&blk)
306
- end
293
+ clear_backlog.call(&blk) if highest_id
307
294
  @subscribed = true
308
295
  end
309
296
 
310
- on.unsubscribe do
311
- @subscribed = false
312
- end
297
+ on.unsubscribe { @subscribed = false }
313
298
 
314
299
  on.message do |_c, m|
315
300
  if m == UNSUB_MESSAGE
@@ -346,28 +331,30 @@ LUA
346
331
  private
347
332
 
348
333
  def new_redis_connection
349
- config = @redis_config.filter do |k, v|
350
- # This is not ideal, required for Redis gem version 5
351
- # redis-client no longer accepts arbitrary params
352
- # anything unknown will error out.
353
- # https://github.com/redis-rb/redis-client/blob/4c8e05acfb3477c1651138a4924616e79e6116f2/lib/redis_client/config.rb#L21-L39
354
- #
355
- #
356
- # We should be doing the opposite and allowlisting params
357
- # or splitting the object up. Starting with the smallest change that is backwards compatible
358
- ![
359
- :backend,
360
- :logger,
361
- :long_polling_enabled,
362
- :backend_options,
363
- :base_route,
364
- :client_message_filters,
365
- :site_id_lookup,
366
- :group_id_lookup,
367
- :user_id_lookup,
368
- :transport_codec
369
- ].include?(k)
370
- end
334
+ config =
335
+ @redis_config.filter do |k, v|
336
+ # This is not ideal, required for Redis gem version 5
337
+ # redis-client no longer accepts arbitrary params
338
+ # anything unknown will error out.
339
+ # https://github.com/redis-rb/redis-client/blob/4c8e05acfb3477c1651138a4924616e79e6116f2/lib/redis_client/config.rb#L21-L39
340
+ #
341
+ #
342
+ # We should be doing the opposite and allowlisting params
343
+ # or splitting the object up. Starting with the smallest change that is backwards compatible
344
+ !%i[
345
+ backend
346
+ logger
347
+ long_polling_enabled
348
+ long_polling_interval
349
+ backend_options
350
+ base_route
351
+ client_message_filters
352
+ site_id_lookup
353
+ group_ids_lookup
354
+ user_id_lookup
355
+ transport_codec
356
+ ].include?(k)
357
+ end
371
358
  ::Redis.new(config)
372
359
  end
373
360
 
@@ -398,9 +385,7 @@ LUA
398
385
  end
399
386
 
400
387
  def process_global_backlog(highest_id, raise_error)
401
- if highest_id > pub_redis.get(global_id_key).to_i
402
- highest_id = 0
403
- end
388
+ highest_id = 0 if highest_id > pub_redis.get(global_id_key).to_i
404
389
 
405
390
  global_backlog(highest_id).each do |old|
406
391
  if highest_id + 1 == old.global_id
@@ -443,19 +428,21 @@ LUA
443
428
  if e.message =~ /^READONLY/
444
429
  try_again = true
445
430
  else
446
- @logger.warn("Dropping undeliverable message: #{e.message}\n#{e.backtrace.join('\n')}")
431
+ @logger.warn(
432
+ "Dropping undeliverable message: #{e.message}\n#{e.backtrace.join('\n')}",
433
+ )
447
434
  end
448
435
  rescue => e
449
- @logger.warn("Dropping undeliverable message: #{e.message}\n#{e.backtrace.join('\n')}")
436
+ @logger.warn(
437
+ "Dropping undeliverable message: #{e.message}\n#{e.backtrace.join('\n')}",
438
+ )
450
439
  end
451
440
 
452
441
  @in_memory_backlog.delete_at(0) unless try_again
453
442
  end
454
443
  end
455
444
  ensure
456
- @lock.synchronize do
457
- @flush_backlog_thread = nil
458
- end
445
+ @lock.synchronize { @flush_backlog_thread = nil }
459
446
  end
460
447
 
461
448
  def cached_eval(redis, script, script_sha1, params)
@@ -478,10 +465,10 @@ LUA
478
465
  # in case we are not connected to the correct server
479
466
  # which can happen when sharing ips
480
467
  pub_redis.disconnect!
481
- pub_redis.set(key, '1')
468
+ pub_redis.set(key, "1")
482
469
  false
483
470
  rescue ::Redis::CommandError => e
484
- return true if e.message =~ /^READONLY/
471
+ true if e.message =~ /^READONLY/
485
472
  end
486
473
  end
487
474
 
@@ -199,7 +199,9 @@ class MessageBus::Rack::Middleware
199
199
  # ConnectionManagement in Rails puts a BodyProxy around stuff
200
200
  # this means connections are not returned until rack.async is
201
201
  # closed
202
- if defined? ActiveRecord::Base.clear_active_connections!
202
+ if defined? ActiveRecord::Base.connection_handler
203
+ ActiveRecord::Base.connection_handler.clear_active_connections!
204
+ elsif defined? ActiveRecord::Base.clear_active_connections!
203
205
  ActiveRecord::Base.clear_active_connections!
204
206
  end
205
207
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MessageBus
4
- VERSION = "4.3.6"
4
+ VERSION = "4.3.8"
5
5
  end
data/package-lock.json CHANGED
@@ -2003,9 +2003,9 @@
2003
2003
  }
2004
2004
  },
2005
2005
  "node_modules/word-wrap": {
2006
- "version": "1.2.3",
2007
- "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",
2008
- "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==",
2006
+ "version": "1.2.4",
2007
+ "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.4.tgz",
2008
+ "integrity": "sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA==",
2009
2009
  "dev": true,
2010
2010
  "engines": {
2011
2011
  "node": ">=0.10.0"
@@ -3553,9 +3553,9 @@
3553
3553
  }
3554
3554
  },
3555
3555
  "word-wrap": {
3556
- "version": "1.2.3",
3557
- "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",
3558
- "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==",
3556
+ "version": "1.2.4",
3557
+ "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.4.tgz",
3558
+ "integrity": "sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA==",
3559
3559
  "dev": true
3560
3560
  },
3561
3561
  "wrappy": {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: message_bus
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.6
4
+ version: 4.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-28 00:00:00.000000000 Z
11
+ date: 2023-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack