Skip to content

Commit

Permalink
Merge pull request #29 from ivx/fix-signal-traps
Browse files Browse the repository at this point in the history
Fix signal traps
  • Loading branch information
hrabe authored Sep 8, 2023
2 parents f5ed8e2 + b51a98f commit a56a383
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.11.1 (2023-09-08)

- Bugfix: trapped signals INT and TERM now calls correctly previous set signal handler

## 0.11.0 (2023-05-30)

- **[Breaking]**: Provide the Bunny connection option `recovery_attempts` in Ears configuration. It
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
ears (0.11.0)
ears (0.11.1)
bunny (~> 2.22.0)
multi_json

Expand Down
20 changes: 16 additions & 4 deletions lib/ears.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ def setup(&block)
# Blocks the calling thread until +SIGTERM+ or +SIGINT+ is received.
# Used to keep the process alive while processing messages.
def run!
running = true
Signal.trap('INT') { running = false }
Signal.trap('TERM') { running = false }
sleep 1 while running && @error.nil?
@running = true
setup_traps
sleep 1 while @running && @error.nil?
raise @error if @error
end

Expand Down Expand Up @@ -82,6 +81,19 @@ def reset!

private

def setup_traps
@previous_int_trap =
Signal.trap('INT') do
@running = false
@previous_int_trap&.call unless @previous_int_trap == 'DEFAULT'
end
@previous_term_trap =
Signal.trap('TERM') do
@running = false
@previous_term_trap&.call unless @previous_term_trap == 'DEFAULT'
end
end

def connection_config
{
connection_name: configuration.connection_name,
Expand Down
2 changes: 1 addition & 1 deletion lib/ears/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Ears
VERSION = '0.11.0'
VERSION = '0.11.1'
end

0 comments on commit a56a383

Please sign in to comment.