]> git.ipfire.org Git - pakfire.git/commitdiff
daemon: Send the IDs of all running jobs
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 3 May 2025 12:52:13 +0000 (12:52 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 3 May 2025 12:52:13 +0000 (12:52 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/daemon.c
src/pakfire/job.c
src/pakfire/job.h

index f58a28380cbda1a22df303ff9e58341d9b06b19e..9a7f2ecb443018c2deeca33dee05fdd10daddfe6 100644 (file)
@@ -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);
index bc3c7ccbba12dbc5362ad12e4f43df37688bb1d0..120662a087b89095b6e73f6f4f323c39201cac09 100644 (file)
@@ -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);
 }
index 6b99824afd47bdd33915bd4feef8d0f81c83794b..967ab173072ca27ee9044e854327871b9c952328 100644 (file)
@@ -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