harmoniser 0.7.0 → 0.8.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: 64be8cb27f910668f1c7d88a546d87b9775f75cfc5a6626ecb6e825409dbc7a4
4
- data.tar.gz: 0b82a72f0e80548db66341adf5748654f7751f3b74a08fa2e5613c043876d8fc
3
+ metadata.gz: 70ec58eff8c88413ab7fa010d6910f9d528a8de1e16fda2a3d2310b09962bd3b
4
+ data.tar.gz: ff15c7cbd71753b0810318a7368618ceec12fe7316a01402bd15dd29cf6259ed
5
5
  SHA512:
6
- metadata.gz: ef1b871763652b0090be1248c259c94846e8132925f6346051b51d4b0d4d2a95a758d5c8762edbb22793ae5c7f9e2e3fafbc1d108551854005d695a79a5927f8
7
- data.tar.gz: 79643c9b0a50769cc7968740bbb3f6aba2461c3800a136651b1206b523e7fbb8768f9ceac85dba83f0b3a029923d9a148cf0c60bde1397385d449e845899386e
6
+ metadata.gz: 1e78c657e2b557d4118f25944c57c706d9af3f2968ecee40d71d5745bee1a6e9a32be4e1d705c67f9a475607cc6a1987383208b571f1f1c22facfacc5428e1e5
7
+ data.tar.gz: b35014311fa351fe77c8743feac5f9b6e68acc2ef0ee4ffb6b203de5f2ebcebdec43d97c9955036f018e8050792e6bbb4ca0459100eddeffbb0ac98a800f476f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.8.0] - 2024-03-31
4
+
5
+ ### Added
6
+ - Implement retry mechanism to establish connection to RabbitMQ. More details at [issue](https://github.com/jollopre/harmoniser/issues/39).
7
+ - Strengthen at_exit hook to not break when connection cannot be closed.
8
+
3
9
  ## [0.7.0] - 2024-01-03
4
10
 
5
11
  ### Added
@@ -22,7 +22,6 @@ module Harmoniser
22
22
 
23
23
  def call
24
24
  parse_options
25
- define_signals
26
25
  run
27
26
  end
28
27
 
@@ -50,6 +49,8 @@ module Harmoniser
50
49
  .new(configuration: configuration, logger: logger)
51
50
  .start
52
51
 
52
+ define_signals
53
+
53
54
  while @read_io.wait_readable
54
55
  signal = @read_io.gets.strip
55
56
  handle_signal(signal)
@@ -37,11 +37,10 @@ module Harmoniser
37
37
  logger = Harmoniser.logger
38
38
 
39
39
  logger.info("Shutting down!")
40
- if connection? && connection.open?
41
- stringified_connection = connection.to_s
42
- logger.info("Connection will be closed: connection = `#{stringified_connection}`")
43
- connection.close
44
- logger.info("Connection closed: connection = `#{stringified_connection}`")
40
+ if connection? && @connection.open?
41
+ logger.info("Connection will be closed: connection = `#{@connection}`")
42
+ @connection.close
43
+ logger.info("Connection closed: connection = `#{@connection}`")
45
44
  end
46
45
  logger.info("Bye!")
47
46
  end
@@ -27,7 +27,7 @@ module Harmoniser
27
27
  write_timeout: 5
28
28
  }
29
29
 
30
- def_delegators :@bunny, :close, :create_channel, :open?, :recovering_from_network_failure?, :start
30
+ def_delegators :@bunny, :create_channel, :open?, :recovering_from_network_failure?
31
31
 
32
32
  def initialize(opts)
33
33
  @bunny = Bunny.new(opts)
@@ -37,6 +37,26 @@ module Harmoniser
37
37
  "<#{self.class.name}>: #{user}@#{host}:#{port}, connection_name = `#{connection_name}`, vhost = `#{vhost}`"
38
38
  end
39
39
 
40
+ def start
41
+ retries = 0
42
+ begin
43
+ with_signal_handler { @bunny.start }
44
+ rescue => e
45
+ Harmoniser.logger.error("Connection attempt failed: retries = `#{retries}`, error_class = `#{e.class}`, error_message = `#{e.message}`")
46
+ with_signal_handler { sleep(1) }
47
+ retries += 1
48
+ retry
49
+ end
50
+ end
51
+
52
+ def close
53
+ @bunny.close
54
+ true
55
+ rescue => e
56
+ Harmoniser.logger.error("Connection#close failed: error_class = `#{e.class}`, error_message = `#{e.message}`")
57
+ false
58
+ end
59
+
40
60
  private
41
61
 
42
62
  def connection_name
@@ -58,5 +78,12 @@ module Harmoniser
58
78
  def vhost
59
79
  @bunny.vhost
60
80
  end
81
+
82
+ def with_signal_handler
83
+ yield if block_given?
84
+ rescue SignalException => e
85
+ Harmoniser.logger.info("Signal received: signal = `#{Signal.signame(e.signo)}`")
86
+ exit(0)
87
+ end
61
88
  end
62
89
  end
@@ -1,3 +1,3 @@
1
1
  module Harmoniser
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harmoniser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jose Lloret
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-03 00:00:00.000000000 Z
11
+ date: 2024-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny