You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am currently writing a plugin for Fluentd using this gem. The issue that I ran into is, I couldn't find a good way to break out of Journal#watch. In other words:
defstart@journal=Systemd::Journal.new@journal.watchdo |entry|
# do stuff ehreendend
and this "start" method is run in a different event loop (using Cool.io). What I want to do is, in the corresponding "shutdown" method, stop the watch loop like this (shutdown is invoked when there is a INT/KILL signal.
defshutdown# somehow stop @journal.watchend
Is this something possible? If there is a better way to go about it, pointers is hugely appreciated.
The text was updated successfully, but these errors were encountered:
Yes, watch does not return and in particular uses a systemd journal API that blocks inside C code, and so cannot be interrupted from ruby land. In particular watch is implemented something like this:
loopdoifjournal.wait# something happened - wake up!yieldjournal.current_entrywhilejournal.move_nextendend
You can do something similar and pass a timeout value to wait so that it will wake up even if nothing changed every so often, so you can check if you need to exit (untested example below):
whileshould_i_keep_running?ifjournal.wait(3_000_000)# wake up at least every 3 secondsyieldjournal.current_entrywhilejournal.move_nextendend
Additionally, if you need to handle signals interrupting wait, you can pass select: true as a second parameter. This uses IO.select to wait for things to change from the ruby side, so it can be interrupted, unlike normal wait. Note that this won't work on JRuby.
I am currently writing a plugin for Fluentd using this gem. The issue that I ran into is, I couldn't find a good way to break out of Journal#watch. In other words:
and this "start" method is run in a different event loop (using Cool.io). What I want to do is, in the corresponding "shutdown" method, stop the watch loop like this (shutdown is invoked when there is a INT/KILL signal.
Is this something possible? If there is a better way to go about it, pointers is hugely appreciated.
The text was updated successfully, but these errors were encountered: