Skip to content

Get watchdog interval #6

Closed
Closed

Description

@Mr0grog

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.

Activity

  1. agis commented on Jun 26, 2024

    @agis
    Owner

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

  2. added a commit that references this issue on Jun 26, 2024
    ef7c0be
  3. Mr0grog commented on Jun 26, 2024

    @Mr0grog
    ContributorAuthor

    Done! #11

  4. Mr0grog commented on Jul 26, 2024

    @Mr0grog
    ContributorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions