bunny 2.22.0 → 2.23.0

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: 2edd88411f92dbdbb1d06b334006e446d5b3e3fb165f3baae3745bd066cf9651
4
- data.tar.gz: 437032f606bb6f77fee02e65706e615f8a52c0e05467bbe257f1796fcedd624c
3
+ metadata.gz: b33407ce8bf5340f646d7f35f884b991da2c54b1e46e7c8bd31f65e75822cc22
4
+ data.tar.gz: 8b4242b14294c62a4310f6f4921eabb54414d930756495ab1c9130559475593f
5
5
  SHA512:
6
- metadata.gz: 698398dc76ca4e3dd11e3c5dc6b078998f23895bd3d975b01e1329c08c8ff0835cb9691d0108f0f6e13aaa769b870b258ff5e1de1958321be4804ca99b30a0be
7
- data.tar.gz: 2a1fdcc61d683a991d07f601a986c5bc04d40cdd7155a1833dc7dba46be014c23d36612c505531b2f2adfe08ed057d6a493cbf5df368318205ffaf88659a88fb
6
+ metadata.gz: 7ecfba958caee454e1105cd500a1d2f632340b8358469420802b8fbf029abdedc742bdae39ff9d2ad1b04cc4a7d7fd6bc26b1ff11fc282118c6c05fb688ff661
7
+ data.tar.gz: 7b101718ac037ad85702432cdf865310e94c5a269348ceee714bc6e5630312415f87283360dbbe88577fa1b661ecc5e5f8086d59bbdd50098cfe5e528c757ea1
data/lib/bunny/channel.rb CHANGED
@@ -1536,7 +1536,8 @@ module Bunny
1536
1536
  # @return [String] Unique string.
1537
1537
  # @api plugin
1538
1538
  def generate_consumer_tag(name = "bunny")
1539
- "#{name}-#{Time.now.to_i * 1000}-#{Kernel.rand(999_999_999_999)}"
1539
+ t = Bunny::Timestamp.now
1540
+ "#{name}-#{t.to_i * 1000}-#{Kernel.rand(999_999_999_999)}"
1540
1541
  end
1541
1542
 
1542
1543
  # @endgroup
@@ -1819,7 +1820,7 @@ module Bunny
1819
1820
 
1820
1821
  # @private
1821
1822
  def channel_level_exception_after_operation_that_has_no_response?(method)
1822
- method.reply_code == 406 && method.reply_text =~ /unknown delivery tag/
1823
+ method.reply_code == 406 && (method.reply_text =~ /unknown delivery tag/ || method.reply_text =~ /delivery acknowledgement on channel \d+ timed out/)
1823
1824
  end
1824
1825
 
1825
1826
  # @private
@@ -25,18 +25,19 @@ module Bunny
25
25
  end
26
26
 
27
27
  def poll(timeout_in_ms = nil)
28
- timeout = timeout_in_ms ? timeout_in_ms / 1000.0 : nil
28
+ timeout_in_sec = timeout_in_ms ? timeout_in_ms / 1000.0 : nil
29
29
 
30
30
  @lock.synchronize do
31
- timeout_strikes_at = Time.now.utc + (timeout || 0)
31
+ started_at = Bunny::Timestamp.monotonic
32
32
  while @q.empty?
33
- wait = if timeout
34
- timeout_strikes_at - Time.now.utc
35
- else
36
- nil
37
- end
38
- @cond.wait(@lock, wait)
39
- raise ::Timeout::Error if wait && Time.now.utc >= timeout_strikes_at
33
+ wait = !(timeout_in_sec.nil?)
34
+ @cond.wait(@lock, timeout_in_sec)
35
+
36
+ if wait
37
+ ended_at = Bunny::Timestamp.monotonic
38
+ elapsed = ended_at - started_at
39
+ raise ::Timeout::Error if (elapsed > timeout_in_sec)
40
+ end
40
41
  end
41
42
  item = @q.shift
42
43
  item
@@ -8,7 +8,8 @@ module Bunny
8
8
 
9
9
  # @return [String] Generated consumer tag
10
10
  def generate
11
- "#{Kernel.rand}-#{Time.now.to_i * 1000}-#{Kernel.rand(999_999_999_999)}"
11
+ t = Bunny::Timestamp.now
12
+ "#{Kernel.rand}-#{t.to_i * 1000}-#{Kernel.rand(999_999_999_999)}"
12
13
  end # generate
13
14
 
14
15
 
@@ -17,7 +18,8 @@ module Bunny
17
18
  # @return [String] Unique string.
18
19
  # @api public
19
20
  def generate_prefixed(name = "bunny")
20
- "#{name}-#{Time.now.to_i * 1000}-#{Kernel.rand(999_999_999_999)}"
21
+ t = Bunny::Timestamp.now
22
+ "#{name}-#{t.to_i * 1000}-#{Kernel.rand(999_999_999_999)}"
21
23
  end
22
24
  end
23
25
  end
@@ -17,7 +17,7 @@ module Bunny
17
17
  @logger = logger
18
18
  @mutex = Monitor.new
19
19
 
20
- @last_activity_time = Time.now
20
+ @last_activity_time = Bunny::Timestamp.monotonic
21
21
  end
22
22
 
23
23
  def start(period = 30)
@@ -38,7 +38,7 @@ module Bunny
38
38
  end
39
39
 
40
40
  def signal_activity!
41
- @last_activity_time = Time.now
41
+ @last_activity_time = Bunny::Timestamp.monotonic
42
42
  end
43
43
 
44
44
  protected
@@ -53,14 +53,14 @@ module Bunny
53
53
  rescue IOError => ioe
54
54
  @logger.error "I/O error in the hearbeat sender: #{ioe.message}"
55
55
  stop
56
- rescue Exception => e
56
+ rescue ::Exception => e
57
57
  @logger.error "Error in the hearbeat sender: #{e.message}"
58
58
  stop
59
59
  end
60
60
  end
61
61
 
62
62
  def beat
63
- now = Time.now
63
+ now = Bunny::Timestamp.monotonic
64
64
 
65
65
  if now > (@last_activity_time + @interval)
66
66
  @logger.debug { "Sending a heartbeat, last activity time: #{@last_activity_time}, interval (s): #{@interval}" }
@@ -0,0 +1,22 @@
1
+ module Bunny
2
+ # Abstracts away the Ruby (OS) method of retriving timestamps.
3
+ #
4
+ # @private
5
+ class Timestamp
6
+ def self.now
7
+ ::Time.now
8
+ end
9
+
10
+ def self.monotonic
11
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
12
+ end
13
+
14
+ def self.non_monotonic
15
+ ::Time.now
16
+ end
17
+
18
+ def self.non_monotonic_utc
19
+ self.non_monotonic.utc
20
+ end
21
+ end
22
+ end
data/lib/bunny/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Bunny
4
4
  # @return [String] Version of the library
5
- VERSION = "2.22.0"
5
+ VERSION = "2.23.0"
6
6
  end
data/lib/bunny.rb CHANGED
@@ -10,7 +10,7 @@ require "bunny/framing"
10
10
  require "bunny/exceptions"
11
11
 
12
12
  require "bunny/socket"
13
-
13
+ require "bunny/timestamp"
14
14
  require "bunny/timeout"
15
15
 
16
16
  begin
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bunny
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.22.0
4
+ version: 2.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Duncan
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2023-06-12 00:00:00.000000000 Z
15
+ date: 2024-07-01 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: amq-protocol
@@ -98,13 +98,15 @@ files:
98
98
  - lib/bunny/ssl_socket.rb
99
99
  - lib/bunny/test_kit.rb
100
100
  - lib/bunny/timeout.rb
101
+ - lib/bunny/timestamp.rb
101
102
  - lib/bunny/transport.rb
102
103
  - lib/bunny/version.rb
103
104
  - lib/bunny/versioned_delivery_tag.rb
104
105
  homepage: http://rubybunny.info
105
106
  licenses:
106
107
  - MIT
107
- metadata: {}
108
+ metadata:
109
+ changelog_uri: https://github.com/ruby-amqp/bunny/blob/main/ChangeLog.md
108
110
  post_install_message:
109
111
  rdoc_options: []
110
112
  require_paths:
@@ -120,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
122
  - !ruby/object:Gem::Version
121
123
  version: '0'
122
124
  requirements: []
123
- rubygems_version: 3.5.0.dev
125
+ rubygems_version: 3.5.9
124
126
  signing_key:
125
127
  specification_version: 4
126
128
  summary: Popular easy to use Ruby client for RabbitMQ