sd_event_source* connect_timer;
unsigned int reconnect_holdoff;
+ // Timer for submitting stats
+ sd_event_source* stat_timer;
+
// Workers
struct pakfire_worker* workers[MAX_WORKERS];
unsigned int running_workers;
return r;
}
+static int pakfire_daemon_submit_stats(sd_event_source* s, uint64_t usec, void* data) {
+ struct pakfire_daemon* daemon = data;
+ int r;
+
+ // Submit stats
+ r = pakfire_buildservice_submit_stats(daemon->service);
+ if (r < 0)
+ CTX_ERROR(daemon->ctx, "Could not submit stats: %s\n", strerror(-r));
+
+ // If we have any workers running, we will submit our stats
+ // every five seconds, otherwise 30 seconds is enough.
+ uint64_t next = (daemon->running_workers > 0) ? 5000000 : 30000000;
+
+ // Reset the timer
+ r = sd_event_source_set_time_relative(daemon->stat_timer, next);
+ if (r < 0) {
+ CTX_ERROR(daemon->ctx, "Could not set the stat timer: %s\n", strerror(-r));
+ return r;
+ }
+
+ // Activate the timer
+ r = sd_event_source_set_enabled(daemon->stat_timer, SD_EVENT_ONESHOT);
+ if (r < 0) {
+ CTX_ERROR(daemon->ctx, "Could not activate the stat timer: %s\n", strerror(-r));
+ return r;
+ }
+
+ return r;
+}
+
static int pakfire_daemon_setup_loop(struct pakfire_daemon* daemon) {
int r;
return r;
}
+ // Submit stats
+ r = sd_event_add_time_relative(daemon->loop, &daemon->stat_timer,
+ CLOCK_MONOTONIC, 0, 0, pakfire_daemon_submit_stats, daemon);
+ if (r < 0) {
+ CTX_ERROR(daemon->ctx, "Could not register the stat timer: %s\n", strerror(-r));
+ return r;
+ }
+
return 0;
}
static void pakfire_daemon_free(struct pakfire_daemon* daemon) {
if (daemon->connect_timer)
sd_event_source_unref(daemon->connect_timer);
+ if (daemon->stat_timer)
+ sd_event_source_unref(daemon->stat_timer);
if (daemon->service)
pakfire_buildservice_unref(daemon->service);
if (daemon->loop)