job check one last time for completed job before returning 404

This commit is contained in:
Ruben Fiszel
2025-02-21 19:57:44 +01:00
parent 00cb59e42f
commit 2edf5a08ae
+10 -1
View File
@@ -915,7 +915,16 @@ impl<'a> GetQuery<'a> {
.fetch_queued(db, job_id, workspace_id)
.await?
.map(Job::QueuedJob);
not_found_if_none(job_maybe, "Job", job_id.to_string())
// potential race condition here, if the job was in queue and completed right after the fetch completed, so we need to check one last time
if let Some(job) = job_maybe {
return Ok(job);
} else {
let cjob2 = self
.fetch_completed(db, job_id, workspace_id)
.await?
.map(Job::CompletedJob);
not_found_if_none(cjob2, "Job", job_id.to_string())
}
}
}
}