]> git.ipfire.org Git - pakfire.git/commitdiff
job: Handle message to abort a build job
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 Feb 2025 09:34:41 +0000 (09:34 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 Feb 2025 09:34:41 +0000 (09:34 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/job.c

index 2505c1a603197bfecd22233c177a02d6b4511622..736937680599897da70c80e6cab4b5d65a0da609 100644 (file)
@@ -977,9 +977,26 @@ int pakfire_job_terminate(struct pakfire_job* job, int signal) {
 }
 
 int pakfire_job_handle_message(struct pakfire_job* self, struct json_object* message) {
+       const char* command = NULL;
+       int r;
+
        DEBUG(self->ctx, "Message received for job %s\n", self->id);
 
-       return 0; // XXX TODO
+       // Fetch the command
+       r = pakfire_json_get_string(message, "command", &command);
+       if (r < 0) {
+               ERROR(self->ctx, "Malformed job message does not contain a command\n");
+               return r;
+       }
+
+       // Abort job
+       if (pakfire_string_equals(command, "abort"))
+               return pakfire_job_terminate(self, SIGTERM);
+
+       // Log an error if we have received an unknown command
+       ERROR(self->ctx, "Unhandled command for job %s: %s\n", self->id, command);
+
+       return 0;
 }
 
 #endif /* CURL_HAS_WEBSOCKETS */