harmoniser 0.11.0 → 0.12.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: a1a7c351ba8ed80091b6e32dbd3cb0486f6b4123b30de12f1406862f3bdedcbb
4
- data.tar.gz: f3d68be4e8cc7cb83e5df89bbc20ce4bc905b44711d59a23de50e7ac761bc5ae
3
+ metadata.gz: f9feb1146437db2d23bb56ef1a72e47ef0912dbbc02b776c2ef026db44dc687e
4
+ data.tar.gz: 79dfe110ea228ba5ae58062c575768c8cc5747228a7a4a5432c36a686da7113d
5
5
  SHA512:
6
- metadata.gz: 5c6da5317a0ea480766ce716b7710598d6a1720afd8bb24cf82f2aecd3b96e9d41b31b3246d306c525e5ddbb5532f8adb87c7b3188a402ecada8c87a192176fb
7
- data.tar.gz: 9a31ed8616f30072245dbc783692cadf871c46f2082f627420fd71a38f6e29b3d9162b6152fdf741173a67e4a16fb5d1c8fbe812eaffb081356f4b83796ad510
6
+ metadata.gz: 47e94a951a8200b1e2ce2287f4fad5d4dda4ac6d4bf4d4e21a7f0bb03a51c8d95a949f0ef8dccc1f873558741ece21a0de89198d0d4325228869b0ad985d098a
7
+ data.tar.gz: d7d11b42621ce764702a408a3c1f789326cef84dfa15ad24d6f8c84ba5b2cd28ce4f4ca1496fd38bfc1aedb1a0d89381adf19825c76ef6d310389173782a03bd
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.12.0] - 2024-12-22
4
+
5
+ ### Changed
6
+ - Perform retries connecting to RabbitMQ only if Harmoniser runs as the main process
7
+ - Change from IO.pipe to Thread::Queue so that an OS signal is exchanged through a queue safely.
8
+
3
9
  ## [0.11.0] - 2024-10-09
4
10
 
5
11
  ### Added
@@ -20,6 +20,7 @@ module Harmoniser
20
20
  def initialize
21
21
  @configuration = Harmoniser.default_configuration
22
22
  @logger = Harmoniser.logger
23
+ @queue = Thread::Queue.new
23
24
  end
24
25
 
25
26
  def call
@@ -38,39 +39,43 @@ module Harmoniser
38
39
  end
39
40
 
40
41
  def define_signals
41
- @read_io, @write_io = IO.pipe
42
-
43
42
  ["INT", "TERM", "USR1"].each do |sig|
44
43
  Signal.trap(sig) do
45
- @write_io.puts(sig)
44
+ @queue.push(sig)
46
45
  end
47
46
  end
48
47
  end
49
48
 
50
49
  def run
51
- @launcher.start
52
-
53
50
  define_signals
54
-
55
- while @read_io.wait_readable
56
- signal = @read_io.gets.strip
57
- handle_signal(signal)
58
- end
51
+ start_launcher
52
+ await_signal
59
53
  rescue Interrupt
60
- @write_io.close
61
- @read_io.close
62
- @launcher.stop
54
+ stop_launcher
63
55
  exit(0)
64
56
  rescue SigUsr1
65
- @write_io.close
66
- @read_io.close
67
- @launcher.stop
57
+ stop_launcher
68
58
  exit(128 + 10)
69
59
  end
70
60
 
71
- def handle_signal(signal)
61
+ def await_signal
62
+ signal = @queue.pop
72
63
  logger.info("Signal received: signal = `#{signal}`")
73
64
  SIGNAL_HANDLERS[signal].call(self, signal)
74
65
  end
66
+
67
+ def start_launcher
68
+ Thread.new do
69
+ await_signal
70
+ end.tap do |t|
71
+ t.abort_on_exception = true
72
+ t.report_on_exception = false
73
+ @launcher.start
74
+ end.kill
75
+ end
76
+
77
+ def stop_launcher
78
+ @launcher.stop
79
+ end
75
80
  end
76
81
  end
@@ -32,14 +32,19 @@ module Harmoniser
32
32
  "<#{self.class.name}>:#{object_id} #{user}@#{host}:#{port}, connection_name = `#{connection_name}`, vhost = `#{vhost}`"
33
33
  end
34
34
 
35
- # TODO Only perform retries when Harmoniser.server?
36
35
  def start
36
+ return @bunny.start unless Harmoniser.server?
37
+
38
+ retryable_start
39
+ end
40
+
41
+ def retryable_start
37
42
  retries = 0
38
43
  begin
39
- with_signal_handler { @bunny.start }
44
+ @bunny.start
40
45
  rescue => e
41
46
  @logger.error("Connection attempt failed: retries = `#{retries}`, error_class = `#{e.class}`, error_message = `#{e.message}`")
42
- with_signal_handler { sleep(1) }
47
+ sleep(1)
43
48
  retries += 1
44
49
  retry
45
50
  end
@@ -97,13 +102,5 @@ module Harmoniser
97
102
  def vhost
98
103
  @bunny.vhost
99
104
  end
100
-
101
- # TODO Use Signal handler defined at Harmoniser::CLI instead of rescuing SignalException?
102
- def with_signal_handler
103
- yield if block_given?
104
- rescue SignalException => e
105
- @logger.info("Signal received: signal = `#{Signal.signame(e.signo)}`")
106
- Harmoniser.server? ? exit(0) : raise
107
- end
108
105
  end
109
106
  end
@@ -1,3 +1,3 @@
1
1
  module Harmoniser
2
- VERSION = "0.11.0"
2
+ VERSION = "0.12.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.11.0
4
+ version: 0.12.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-10-09 00:00:00.000000000 Z
11
+ date: 2024-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny