harmoniser 0.7.0 → 0.8.1

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: 22ff604975432b081956834ca20441d85c8ae98ce690a6185daea4e0d7a1eb11
4
+ data.tar.gz: 1b5c12440738254845b8f7d717013f5306ea760df126cc702dbce178af9e7f32
5
5
  SHA512:
6
- metadata.gz: ef1b871763652b0090be1248c259c94846e8132925f6346051b51d4b0d4d2a95a758d5c8762edbb22793ae5c7f9e2e3fafbc1d108551854005d695a79a5927f8
7
- data.tar.gz: 79643c9b0a50769cc7968740bbb3f6aba2461c3800a136651b1206b523e7fbb8768f9ceac85dba83f0b3a029923d9a148cf0c60bde1397385d449e845899386e
6
+ metadata.gz: '0568d8afd4545a550a645f016936cc27866973216a20a3aa7cb9b083b8e62ce0fab3e6dca8e1b5dadf8104edc7a7f08a165d1b252dc94fcb0ee631fe489f19d8'
7
+ data.tar.gz: cf2e9b2f429f0bf8a4abf7741f893d732fa8cde55935aa3f518222e1aaf1857313019c6b9f049b4fdf0be8882b5c392a1dc6dbfd70e0048a9826a4af89edcc5e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.8.1] - 2024-04-08
4
+
5
+ ### Fixed
6
+ - Exit ruby process when harmoniser is not the main process. More details at [issue](https://github.com/jollopre/harmoniser/issues/41).
7
+
8
+ ## [0.8.0] - 2024-03-31
9
+
10
+ ### Added
11
+ - Implement retry mechanism to establish connection to RabbitMQ. More details at [issue](https://github.com/jollopre/harmoniser/issues/39).
12
+ - Strengthen at_exit hook to not break when connection cannot be closed.
13
+
3
14
  ## [0.7.0] - 2024-01-03
4
15
 
5
16
  ### 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
+ Harmoniser.server? ? exit(0) : raise
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.1"
3
3
  end
data/lib/harmoniser.rb CHANGED
@@ -7,4 +7,10 @@ require "harmoniser/subscriber"
7
7
  module Harmoniser
8
8
  extend Configurable
9
9
  extend Loggable
10
+
11
+ class << self
12
+ def server?
13
+ !!defined?(CLI)
14
+ end
15
+ end
10
16
  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.1
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-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny