]> git.ipfire.org Git - collecty.git/commitdiff
source: Lower the heartbeat if a source is in error state
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 4 Oct 2025 15:19:11 +0000 (15:19 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 4 Oct 2025 15:19:11 +0000 (15:19 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/source.c

index 1db74a731c5b4e04c26c95b763dfeba1ce2bd56c..8f014a5c8389a96610b0aba17c4bb6feef0ea7d1 100644 (file)
@@ -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;
 }