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

Get watchdog interval #6

Open
Mr0grog opened this issue Aug 4, 2023 · 3 comments · May be fixed by #11
Open

Get watchdog interval #6

Mr0grog opened this issue Aug 4, 2023 · 3 comments · May be fixed by #11

Comments

@Mr0grog
Copy link

Mr0grog commented Aug 4, 2023

I was helping a friend implement watchdog notifications, and noticed that, unlike sd_watchdog_enabled(3), this gem doesn’t have a way to get the configured watchdog interval. Instead, pretty much every Ruby gem or app I’ve seen use this has to implement the same pattern:

def do_watchdog
  return unless SdNotify.watchdog?

  # Divide by 1,000,000 since 99% of Ruby tooling uses seconds, not microseconds.
  interval = Integer(ENV.fetch('WATCHDOG_USEC')) / 1_000_000.0
  loop do
    SdNotify.watchdog
    sleep interval
  end
end

It would be much more convenient (and require less digging around to learn the environment variables) if this gem exposed a method to get the watchdog interval:

def do_watchdog
  return unless SdNotify.watchdog?

  loop do
    SdNotify.watchdog
    sleep SdNotify.watchdog_interval
  end
end

Ideally, I think this would:

  1. Return 0 (or maybe -1?) if the watchdog is not expecting notifications (that is, if SdNotify.watchdog? would have returned false).

  2. Return the number of seconds as a float instead of the number of microseconds as an integer, since almost all use cases will involve doing this anyway.

@agis
Copy link
Owner

agis commented Jun 26, 2024

Sounds like a good idea! Any interested in submitting a PR?

Mr0grog added a commit to Mr0grog/ruby-sdnotify that referenced this issue Jun 26, 2024
This adds a `watchdog_interval` method as well as tests for it and for `watchdog?` (which previously had no tests). I also took the liberty of revising the docs for `watchdog?` to (I hope) be a little clearer.

Fixes agis#6.
@Mr0grog Mr0grog linked a pull request Jun 26, 2024 that will close this issue
@Mr0grog
Copy link
Author

Mr0grog commented Jun 26, 2024

Done! #11

@Mr0grog
Copy link
Author

Mr0grog commented Jul 26, 2024

Hi @agis, this is just a friendly reminder that I posted a PR for this about a month ago: #11. Not sure if you saw it.

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

Successfully merging a pull request may close this issue.

2 participants