I would like to harden it against data loss, i.e. when the script gets interrupted, it should still process the current job and only after finishing it, exit the processing loop and close the connection to the beanstalkd.
If there is no job being processed it would be best to close the connection and immediately exit.
I tried using trap(...) but it requires some jumping through burning hoops to bring the signal into the processing loop.
What is the best way to achieve proper signal handling?
I wrote a small script to multiplex a tube into multiple other tubes: https://github.com/martint17r/beanstalk-multiplex
I would like to harden it against data loss, i.e. when the script gets interrupted, it should still process the current job and only after finishing it, exit the processing loop and close the connection to the beanstalkd. If there is no job being processed it would be best to close the connection and immediately exit.
I tried using trap(...) but it requires some jumping through burning hoops to bring the signal into the processing loop.
What is the best way to achieve proper signal handling?