From: Michael Tremer Date: Sat, 4 Oct 2025 15:19:11 +0000 (+0000) Subject: source: Lower the heartbeat if a source is in error state X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a45b4d971f2b63543d5002e4459fab2e996c6076;p=collecty.git source: Lower the heartbeat if a source is in error state Signed-off-by: Michael Tremer --- diff --git a/src/daemon/source.c b/src/daemon/source.c index 1db74a7..8f014a5 100644 --- a/src/daemon/source.c +++ b/src/daemon/source.c @@ -217,6 +217,7 @@ static int collecty_source_error_detection(collecty_source* self, int result) { static int collecty_source_heartbeat(sd_event_source* source, uint64_t usec, void* data) { collecty_source* self = data; + uint64_t next_heartbeat; int r; DEBUG(self->ctx, "Heartbeat called for %s\n", collecty_source_name(self)); @@ -233,15 +234,34 @@ static int collecty_source_heartbeat(sd_event_source* source, uint64_t usec, voi if (r < 0) return r; + // Determine when to call again + switch (self->state) { + // If we are in error state we might skip this source for a while + case STATE_ERROR: + next_heartbeat = usec + 3600000000; // 1 hr + break; + + // Don't call again if we have been disabled + case STATE_DISABLED: + next_heartbeat = 0; + break; + + // In all other cases, we keep beating + default: + next_heartbeat = usec + HEARTBEAT; + } + // Arm the timer again - r = sd_event_source_set_time(self->events.heartbeat, usec + HEARTBEAT); - if (r < 0) - return r; + if (next_heartbeat) { + r = sd_event_source_set_time(self->events.heartbeat, next_heartbeat); + if (r < 0) + return r; - // Call this continuously - r = sd_event_source_set_enabled(self->events.heartbeat, SD_EVENT_ON); - if (r < 0) - return r; + // Call this continuously + r = sd_event_source_set_enabled(self->events.heartbeat, SD_EVENT_ON); + if (r < 0) + return r; + } return 0; }