]> git.ipfire.org Git - pakfire.git/commitdiff
job: Send an API call once the job has finished
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 28 Jan 2025 16:29:05 +0000 (16:29 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 28 Jan 2025 16:29:05 +0000 (16:29 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/buildservice.c
src/pakfire/buildservice.h
src/pakfire/job.c

index be53e78e146bef3a5274508c6895aae574de77d7..67e602a47fbb0211b0d3bd793241bbff9acbbcda 100644 (file)
@@ -657,49 +657,3 @@ ERROR:
 
        return r;
 }
-
-int pakfire_buildservice_job_finished(struct pakfire_buildservice* service,
-               const char* uuid, int success, const char* logfile, const char** packages) {
-       struct pakfire_xfer* xfer = NULL;
-       int r;
-
-       // Create a new xfer
-       r = pakfire_buildservice_xfer_create(&xfer, service, "/api/v1/jobs/%s", uuid);
-       if (r)
-               goto ERROR;
-
-       // Enable authentication
-       r = pakfire_xfer_auth(xfer);
-       if (r)
-               goto ERROR;
-
-       // Has the job been successful?
-       r = pakfire_xfer_add_param(xfer, "success", "%s", (success) ? "true" : "false");
-       if (r)
-               goto ERROR;
-
-       // Logfile
-       if (logfile) {
-               r = pakfire_xfer_add_param(xfer, "logfile", "%s", logfile);
-               if (r)
-                       goto ERROR;
-       }
-
-       // Packages
-       for (const char** package = packages; *package; package++) {
-               r = pakfire_xfer_add_param(xfer, "package", "%s", *package);
-               if (r)
-                       goto ERROR;
-       }
-
-       // Send the request
-       r = pakfire_xfer_run_api_request(xfer, NULL);
-       if (r)
-               goto ERROR;
-
-ERROR:
-       if (xfer)
-               pakfire_xfer_unref(xfer);
-
-       return r;
-}
index 06fe4c770085d752af9b30f3f29404af58a1ad63..d39381fb187d80a2a8e97d870dfc448e6e07a573 100644 (file)
@@ -64,9 +64,4 @@ int pakfire_buildservice_create_repo(struct pakfire_buildservice* service,
 int pakfire_buildservice_delete_repo(struct pakfire_buildservice* service,
        const char* distro, const char* name);
 
-// Jobs
-
-int pakfire_buildservice_job_finished(struct pakfire_buildservice* service,
-       const char* uuid, int success, const char* logfile, const char** packages);
-
 #endif /* PAKFIRE_BUILDSERVICE_H */
index 4f4303b6658ddab6d46ddfe345f4efae465ed3d0..43dcf747254e3c689eca00463009f5fab8aca1f3 100644 (file)
@@ -290,6 +290,71 @@ ERROR:
        return r;
 }
 
+/*
+       Called when the job has finished with status as the error code.
+*/
+static int pakfire_job_finished(struct pakfire_job* job, int status) {
+       struct pakfire_xfer* xfer = NULL;
+       char job_id[UUID_STR_LEN];
+       int r;
+
+       // Format the job ID as string
+       uuid_unparse(job->job_id, job_id);
+
+       DEBUG(job->ctx, "Job %s has finished with status %d\n", job_id, status);
+
+       // Check if we have any uploads - except for test builds
+       if (!(job->flags & PAKFIRE_JOB_TEST)) {
+               if (!job->uploads) {
+                       ERROR(job->ctx, "There are no uploads\n");
+                       r = -EINVAL;
+                       goto ERROR;
+               }
+       }
+
+       // Create a new xfer
+       r = pakfire_job_xfer_create(&xfer, job, "/api/v1/jobs/%s/finished", job_id);
+       if (r < 0)
+               goto ERROR;
+
+       // Enable authentication
+       r = pakfire_xfer_auth(xfer);
+       if (r < 0)
+               goto ERROR;
+
+       // Has the job been successful?
+       r = pakfire_xfer_add_param(xfer, "success", "%s", (status == 0) ? "true" : "false");
+       if (r < 0)
+               goto ERROR;
+
+#if 0
+       // Logfile
+       if (logfile) {
+               r = pakfire_xfer_add_param(xfer, "logfile", "%s", logfile);
+               if (r)
+                       goto ERROR;
+       }
+#endif
+
+       // Packages
+       for (char** upload = job->uploads; *upload; upload++) {
+               r = pakfire_xfer_add_param(xfer, "package", "%s", *upload);
+               if (r < 0)
+                       goto ERROR;
+       }
+
+       // Send the request
+       r = pakfire_xfer_run_api_request(xfer, NULL);
+       if (r < 0)
+               goto ERROR;
+
+ERROR:
+       if (xfer)
+               pakfire_xfer_unref(xfer);
+
+       return r;
+}
+
 static int pakfire_job_crashed(struct pakfire_job* job, const siginfo_t* si) {
        struct pakfire_xfer* xfer = NULL;
        char job_id[UUID_STR_LEN];
@@ -420,7 +485,6 @@ static int pakfire_job_exited(sd_event_source* s, const siginfo_t* si, void* dat
 
                        // Update state
                        job->state = PAKFIRE_JOB_STATE_EXITED;
-
                        break;
 
                case CLD_KILLED:
@@ -589,6 +653,11 @@ static int pakfire_job_child(struct pakfire_job* job) {
        // Run the build
        r = pakfire_build_exec(build, job->pkg, pakfire_job_result, job);
 
+       // Signal that the job has finished
+       r = pakfire_job_finished(job, r);
+       if (r < 0)
+               goto ERROR;
+
 ERROR:
        if (build)
                pakfire_build_unref(build);