Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle sigterm? #145

Open
9mm opened this issue May 28, 2022 · 2 comments
Open

How to handle sigterm? #145

9mm opened this issue May 28, 2022 · 2 comments

Comments

@9mm
Copy link

9mm commented May 28, 2022

I'm using this in a sidekiq job (not the best place for it I realize, in the name of time I'm not daemonizing)

The only thing is, is there a way I can check something inside the local loop in the gem?

This obviously only works when there's a message, but otherwise it will get SIGKILL

      client.get do |topic, message|
        break if $sidekiq_shutdown_pending
        puts topic, message
      end
@softwaregravy
Copy link

You can rescue interrupts in Ruby. Here's a blogpost (not mine) talking a bit about it. So you'd have to wrap the code in a begin block and then rescue the interrupt.

If instead of what you have there, you were to do:

MQTT::Client.connect(...) do |c|
   ...
end

Then your code would be wrapped in an ensure block which should exit cleanly.

@9mm
Copy link
Author

9mm commented Jul 1, 2022

awesome thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants