From: Michael Tremer Date: Sat, 3 May 2025 12:52:13 +0000 (+0000) Subject: daemon: Send the IDs of all running jobs X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a52bb6a46aafdab84c80e6e66eae6c8e1c01af3d;p=pakfire.git daemon: Send the IDs of all running jobs Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/daemon.c b/src/pakfire/daemon.c index f58a2838..9a7f2ecb 100644 --- a/src/pakfire/daemon.c +++ b/src/pakfire/daemon.c @@ -775,6 +775,7 @@ static int pakfire_daemon_connect(sd_event_source* s, uint64_t usec, void* data) struct pakfire_cpuinfo cpuinfo = {}; struct pakfire_xfer* xfer = NULL; const char* arch = NULL; + const char* id = NULL; int r; DEBUG(daemon->ctx, "Connecting...\n"); @@ -860,6 +861,22 @@ static int pakfire_daemon_connect(sd_event_source* s, uint64_t usec, void* data) if (r < 0) goto ERROR; + // Add all running jobs + for (unsigned int i = 0; i < MAX_JOBS; i++) { + if (!daemon->jobs[i]) + break; + + // Fetch the job ID + id = pakfire_job_get_id(daemon->jobs[i]); + if (!id) + continue; + + // Add the job ID to the query + r = pakfire_xfer_add_query(xfer, "jobs", "%s", id); + if (r < 0) + goto ERROR; + } + // Make this a WebSocket connection r = pakfire_xfer_socket(xfer, pakfire_daemon_connected, pakfire_daemon_recv, pakfire_daemon_send, pakfire_daemon_close, daemon); diff --git a/src/pakfire/job.c b/src/pakfire/job.c index bc3c7ccb..120662a0 100644 --- a/src/pakfire/job.c +++ b/src/pakfire/job.c @@ -945,6 +945,10 @@ struct pakfire_job* pakfire_job_unref(struct pakfire_job* job) { return NULL; } +const char* pakfire_job_get_id(struct pakfire_job* self) { + return self->id; +} + int pakfire_job_has_id(struct pakfire_job* job, const char* id) { return pakfire_string_equals(job->id, id); } diff --git a/src/pakfire/job.h b/src/pakfire/job.h index 6b99824a..967ab173 100644 --- a/src/pakfire/job.h +++ b/src/pakfire/job.h @@ -33,6 +33,7 @@ struct pakfire_job* pakfire_job_ref(struct pakfire_job* worker); struct pakfire_job* pakfire_job_unref(struct pakfire_job* worker); // ID +const char* pakfire_job_get_id(struct pakfire_job* self); int pakfire_job_has_id(struct pakfire_job* job, const char* id); // Launch