# HG changeset patch # User Alain Mazy # Date 1689843094 -7200 # Node ID b5f2122a133479fff4115e318566b13e4219ae6f # Parent 78aad3916da48d976204ea974a5030e89c966494 Added a route to delete completed jobs from history: DELETE /jobs/{id} diff -r 78aad3916da4 -r b5f2122a1334 NEWS --- a/NEWS Thu Jul 13 19:33:10 2023 +0200 +++ b/NEWS Thu Jul 20 10:51:34 2023 +0200 @@ -6,6 +6,12 @@ * Prevent the leak of the full path of the source files in the binaries +REST API +-------- + +* API version upgraded to 22 +* Added a route to delete completed jobs from history: DELETE /jobs/{id} + Version 1.12.1 (2023-07-04) =========================== diff -r 78aad3916da4 -r b5f2122a1334 OrthancFramework/Sources/JobsEngine/IJob.h --- a/OrthancFramework/Sources/JobsEngine/IJob.h Thu Jul 13 19:33:10 2023 +0200 +++ b/OrthancFramework/Sources/JobsEngine/IJob.h Thu Jul 20 10:51:34 2023 +0200 @@ -66,5 +66,9 @@ // This function can only be called if the job has reached its // "success" state virtual bool DeleteOutput(const std::string& key) = 0; + + // This function can only be called if the job has reached its + // "success" state + virtual void DeleteAllOutputs() {} }; } diff -r 78aad3916da4 -r b5f2122a1334 OrthancFramework/Sources/JobsEngine/JobsRegistry.cpp --- a/OrthancFramework/Sources/JobsEngine/JobsRegistry.cpp Thu Jul 13 19:33:10 2023 +0200 +++ b/OrthancFramework/Sources/JobsEngine/JobsRegistry.cpp Thu Jul 20 10:51:34 2023 +0200 @@ -649,6 +649,42 @@ } + bool JobsRegistry::DeleteJobInfo(const std::string& id) + { + LOG(INFO) << "Deleting job: " << id; + + boost::mutex::scoped_lock lock(mutex_); + CheckInvariants(); + + JobsIndex::iterator found = jobsIndex_.find(id); + + if (found == jobsIndex_.end()) + { + LOG(WARNING) << "Unknown job to delete: " << id; + return false; + } + else + { + for (CompletedJobs::iterator it = completedJobs_.begin(); + it != completedJobs_.end(); ++it) + { + if (*it == found->second) + { + found->second->GetJob().DeleteAllOutputs(); + delete found->second; + + completedJobs_.erase(it); + jobsIndex_.erase(id); + return true; + } + } + + LOG(WARNING) << "Can not delete a job that is not complete: " << id; + return false; + } + } + + bool JobsRegistry::GetJobOutput(std::string& output, MimeType& mime, std::string& filename, diff -r 78aad3916da4 -r b5f2122a1334 OrthancFramework/Sources/JobsEngine/JobsRegistry.h --- a/OrthancFramework/Sources/JobsEngine/JobsRegistry.h Thu Jul 13 19:33:10 2023 +0200 +++ b/OrthancFramework/Sources/JobsEngine/JobsRegistry.h Thu Jul 20 10:51:34 2023 +0200 @@ -147,6 +147,8 @@ bool GetJobInfo(JobInfo& target, const std::string& id); + bool DeleteJobInfo(const std::string& id); + bool GetJobOutput(std::string& output, MimeType& mime, std::string& filename, diff -r 78aad3916da4 -r b5f2122a1334 OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp --- a/OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp Thu Jul 13 19:33:10 2023 +0200 +++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestSystem.cpp Thu Jul 20 10:51:34 2023 +0200 @@ -729,6 +729,34 @@ } } + static void DeleteJobInfo(RestApiDeleteCall& call) + { + if (call.IsDocumentation()) + { + call.GetDocumentation() + .SetTag("Jobs") + .SetSummary("Delete a job from history") + .SetDescription("Delete the job from the jobs history. Only a completed job can be deleted. " + "If the job has not run or not completed yet, you must cancel it first. " + "If the job has outputs, all outputs will be deleted as well. ") + .SetUriArgument("id", "Identifier of the job of interest"); + return; + } + + std::string job = call.GetUriComponent("id", ""); + + if (OrthancRestApi::GetContext(call).GetJobsEngine(). + GetRegistry().DeleteJobInfo(job)) + { + call.GetOutput().AnswerBuffer("", MimeType_PlainText); + } + else + { + throw OrthancException(ErrorCode_InexistentItem, + "No job found with this id: " + job); + } + } + static void GetJobOutput(RestApiGetCall& call) { @@ -1138,6 +1166,7 @@ Register("/jobs", ListJobs); Register("/jobs/{id}", GetJobInfo); + Register("/jobs/{id}", DeleteJobInfo); Register("/jobs/{id}/cancel", ApplyJobAction); Register("/jobs/{id}/pause", ApplyJobAction); Register("/jobs/{id}/resubmit", ApplyJobAction); diff -r 78aad3916da4 -r b5f2122a1334 OrthancServer/Sources/ServerJobs/ArchiveJob.cpp --- a/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp Thu Jul 13 19:33:10 2023 +0200 +++ b/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp Thu Jul 20 10:51:34 2023 +0200 @@ -1482,4 +1482,9 @@ return false; } } + + void ArchiveJob::DeleteAllOutputs() + { + DeleteOutput("archive"); + } } diff -r 78aad3916da4 -r b5f2122a1334 OrthancServer/Sources/ServerJobs/ArchiveJob.h --- a/OrthancServer/Sources/ServerJobs/ArchiveJob.h Thu Jul 13 19:33:10 2023 +0200 +++ b/OrthancServer/Sources/ServerJobs/ArchiveJob.h Thu Jul 20 10:51:34 2023 +0200 @@ -122,5 +122,7 @@ const std::string& key) ORTHANC_OVERRIDE; virtual bool DeleteOutput(const std::string& key) ORTHANC_OVERRIDE; + + virtual void DeleteAllOutputs() ORTHANC_OVERRIDE; }; }