Mercurial > hg > orthanc
changeset 2811:7cfc8d266f41
reason for releasing resources in jobs
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 06 Sep 2018 12:32:02 +0200 |
parents | 1e8c4ecd02f4 |
children | ea7aea6f6a95 |
files | Core/Enumerations.h Core/JobsEngine/IJob.h Core/JobsEngine/JobsEngine.cpp Core/JobsEngine/Operations/SequenceOfOperationsJob.cpp Core/JobsEngine/Operations/SequenceOfOperationsJob.h OrthancServer/ServerJobs/ArchiveJob.h OrthancServer/ServerJobs/DicomModalityStoreJob.cpp OrthancServer/ServerJobs/DicomModalityStoreJob.h OrthancServer/ServerJobs/OrthancPeerStoreJob.cpp OrthancServer/ServerJobs/OrthancPeerStoreJob.h OrthancServer/ServerJobs/ResourceModificationJob.h Plugins/Engine/PluginsJob.cpp Plugins/Engine/PluginsJob.h Plugins/Include/orthanc/OrthancCPlugin.h UnitTestsSources/MultiThreadingTests.cpp |
diffstat | 15 files changed, 85 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/Enumerations.h Thu Sep 06 11:06:54 2018 +0200 +++ b/Core/Enumerations.h Thu Sep 06 12:32:02 2018 +0200 @@ -567,6 +567,15 @@ JobStepCode_Retry }; + enum JobReleaseReason + { + JobReleaseReason_Paused, + JobReleaseReason_Canceled, + JobReleaseReason_Success, + JobReleaseReason_Failure, + JobReleaseReason_Retry + }; + /** * WARNING: Do not change the explicit values in the enumerations
--- a/Core/JobsEngine/IJob.h Thu Sep 06 11:06:54 2018 +0200 +++ b/Core/JobsEngine/IJob.h Thu Sep 06 12:32:02 2018 +0200 @@ -55,7 +55,8 @@ // Method called once the job is resubmitted after a failure virtual void SignalResubmit() = 0; - virtual void ReleaseResources() = 0; // For pausing/canceling jobs + // For pausing/canceling jobs + virtual void ReleaseResources(JobReleaseReason reason) = 0; virtual float GetProgress() = 0;
--- a/Core/JobsEngine/JobsEngine.cpp Thu Sep 06 11:06:54 2018 +0200 +++ b/Core/JobsEngine/JobsEngine.cpp Thu Sep 06 12:32:02 2018 +0200 @@ -55,14 +55,14 @@ if (running.IsPauseScheduled()) { - running.GetJob().ReleaseResources(); + running.GetJob().ReleaseResources(JobReleaseReason_Paused); running.MarkPause(); return false; } if (running.IsCancelScheduled()) { - running.GetJob().ReleaseResources(); + running.GetJob().ReleaseResources(JobReleaseReason_Canceled); running.MarkCanceled(); return false; } @@ -89,19 +89,19 @@ switch (result.GetCode()) { case JobStepCode_Success: + running.GetJob().ReleaseResources(JobReleaseReason_Success); running.UpdateStatus(ErrorCode_Success); - running.GetJob().ReleaseResources(); running.MarkSuccess(); return false; case JobStepCode_Failure: - running.GetJob().ReleaseResources(); + running.GetJob().ReleaseResources(JobReleaseReason_Failure); running.UpdateStatus(result.GetFailureCode()); running.MarkFailure(); return false; case JobStepCode_Retry: - running.GetJob().ReleaseResources(); + running.GetJob().ReleaseResources(JobReleaseReason_Retry); running.UpdateStatus(ErrorCode_Success); running.MarkRetry(result.GetRetryTimeout()); return false;
--- a/Core/JobsEngine/Operations/SequenceOfOperationsJob.cpp Thu Sep 06 11:06:54 2018 +0200 +++ b/Core/JobsEngine/Operations/SequenceOfOperationsJob.cpp Thu Sep 06 12:32:02 2018 +0200 @@ -383,7 +383,7 @@ } - void SequenceOfOperationsJob::ReleaseResources() + void SequenceOfOperationsJob::ReleaseResources(JobReleaseReason reason) { boost::mutex::scoped_lock lock(mutex_); connectionManager_.Close();
--- a/Core/JobsEngine/Operations/SequenceOfOperationsJob.h Thu Sep 06 11:06:54 2018 +0200 +++ b/Core/JobsEngine/Operations/SequenceOfOperationsJob.h Thu Sep 06 12:32:02 2018 +0200 @@ -132,7 +132,7 @@ virtual void SignalResubmit(); - virtual void ReleaseResources(); + virtual void ReleaseResources(JobReleaseReason reason); virtual float GetProgress();
--- a/OrthancServer/ServerJobs/ArchiveJob.h Thu Sep 06 11:06:54 2018 +0200 +++ b/OrthancServer/ServerJobs/ArchiveJob.h Thu Sep 06 12:32:02 2018 +0200 @@ -86,7 +86,7 @@ virtual JobStepResult ExecuteStep(); - virtual void ReleaseResources() + virtual void ReleaseResources(JobReleaseReason reason) { }
--- a/OrthancServer/ServerJobs/DicomModalityStoreJob.cpp Thu Sep 06 11:06:54 2018 +0200 +++ b/OrthancServer/ServerJobs/DicomModalityStoreJob.cpp Thu Sep 06 12:32:02 2018 +0200 @@ -164,7 +164,7 @@ } } - void DicomModalityStoreJob::ReleaseResources() // For pausing jobs + void DicomModalityStoreJob::ReleaseResources(JobReleaseReason reason) // For pausing jobs { connection_.reset(NULL); }
--- a/OrthancServer/ServerJobs/DicomModalityStoreJob.h Thu Sep 06 11:06:54 2018 +0200 +++ b/OrthancServer/ServerJobs/DicomModalityStoreJob.h Thu Sep 06 12:32:02 2018 +0200 @@ -87,7 +87,7 @@ void SetMoveOriginator(const std::string& aet, int id); - virtual void ReleaseResources(); + virtual void ReleaseResources(JobReleaseReason reason); virtual void GetJobType(std::string& target) {
--- a/OrthancServer/ServerJobs/OrthancPeerStoreJob.cpp Thu Sep 06 11:06:54 2018 +0200 +++ b/OrthancServer/ServerJobs/OrthancPeerStoreJob.cpp Thu Sep 06 12:32:02 2018 +0200 @@ -87,7 +87,7 @@ } - void OrthancPeerStoreJob::ReleaseResources() // For pausing jobs + void OrthancPeerStoreJob::ReleaseResources(JobReleaseReason reason) // For pausing jobs { client_.reset(NULL); }
--- a/OrthancServer/ServerJobs/OrthancPeerStoreJob.h Thu Sep 06 11:06:54 2018 +0200 +++ b/OrthancServer/ServerJobs/OrthancPeerStoreJob.h Thu Sep 06 12:32:02 2018 +0200 @@ -67,7 +67,7 @@ return peer_; } - virtual void ReleaseResources(); // For pausing jobs + virtual void ReleaseResources(JobReleaseReason reason); // For pausing jobs virtual void GetJobType(std::string& target) {
--- a/OrthancServer/ServerJobs/ResourceModificationJob.h Thu Sep 06 11:06:54 2018 +0200 +++ b/OrthancServer/ServerJobs/ResourceModificationJob.h Thu Sep 06 12:32:02 2018 +0200 @@ -106,7 +106,7 @@ return origin_; } - virtual void ReleaseResources() + virtual void ReleaseResources(JobReleaseReason reason) { }
--- a/Plugins/Engine/PluginsJob.cpp Thu Sep 06 11:06:54 2018 +0200 +++ b/Plugins/Engine/PluginsJob.cpp Thu Sep 06 12:32:02 2018 +0200 @@ -110,7 +110,22 @@ JobStepResult PluginsJob::ExecuteStep() { - + OrthancPluginJobStepStatus status = step_(job_); + + switch (status) + { + case OrthancPluginJobStepStatus_Success: + return JobStepResult::Success(); + + case OrthancPluginJobStepStatus_Failure: + return JobStepResult::Failure(ErrorCode_Plugin); + + case OrthancPluginJobStepStatus_Continue: + return JobStepResult::Continue(); + + default: + throw OrthancException(ErrorCode_ParameterOutOfRange); + } } void PluginsJob::SignalResubmit() @@ -118,9 +133,29 @@ reset_(job_); } - void PluginsJob::ReleaseResources() + void PluginsJob::ReleaseResources(JobReleaseReason reason) { - releaseResources_(job_); + switch (reason) + { + case JobReleaseReason_Success: + releaseResources_(job_, OrthancPluginJobReleaseReason_Success); + break; + + case JobReleaseReason_Failure: + releaseResources_(job_, OrthancPluginJobReleaseReason_Failure); + break; + + case JobReleaseReason_Canceled: + releaseResources_(job_, OrthancPluginJobReleaseReason_Canceled); + break; + + case JobReleaseReason_Paused: + releaseResources_(job_, OrthancPluginJobReleaseReason_Paused); + break; + + default: + throw OrthancException(ErrorCode_ParameterOutOfRange); + } } float PluginsJob::GetProgress()
--- a/Plugins/Engine/PluginsJob.h Thu Sep 06 11:06:54 2018 +0200 +++ b/Plugins/Engine/PluginsJob.h Thu Sep 06 12:32:02 2018 +0200 @@ -67,7 +67,7 @@ virtual void SignalResubmit(); - virtual void ReleaseResources(); + virtual void ReleaseResources(JobReleaseReason reason); virtual float GetProgress();
--- a/Plugins/Include/orthanc/OrthancCPlugin.h Thu Sep 06 11:06:54 2018 +0200 +++ b/Plugins/Include/orthanc/OrthancCPlugin.h Thu Sep 06 12:32:02 2018 +0200 @@ -846,13 +846,28 @@ **/ typedef enum { - OrthancPluginJobStepStatus_Success, /*!< The job has successfully executed all its steps */ - OrthancPluginJobStepStatus_Failure, /*!< The job has failed while executing this step */ - OrthancPluginJobStepStatus_Continue /*!< The job has still data to process after this step */ + OrthancPluginJobStepStatus_Success = 1, /*!< The job has successfully executed all its steps */ + OrthancPluginJobStepStatus_Failure = 2, /*!< The job has failed while executing this step */ + OrthancPluginJobStepStatus_Continue = 3 /*!< The job has still data to process after this step */ } OrthancPluginJobStepStatus; /** + * Explains why the job should release its resources. This is + * especially important to disambiguate between the "paused" + * condition and the "final" conditions (success, failure, or + * canceled). + **/ + typedef enum + { + OrthancPluginJobReleaseReason_Success = 1, /*!< The job has succeeded */ + OrthancPluginJobReleaseReason_Paused = 2, /*!< The job was paused, and will be resumed later */ + OrthancPluginJobReleaseReason_Failure = 3, /*!< The job has failed, and might be resubmitted later */ + OrthancPluginJobReleaseReason_Canceled = 4 /*!< The job was canceled, and might be resubmitted later */ + } OrthancPluginJobReleaseReason; + + + /** * @brief A memory buffer allocated by the core system of Orthanc. * * A memory buffer allocated by the core system of Orthanc. When the @@ -1260,7 +1275,8 @@ typedef void (*OrthancPluginJobFree) (void* job); typedef float (*OrthancPluginJobGetProgress) (void* job); typedef OrthancPluginJobStepStatus (*OrthancPluginJobStep) (void* job); - typedef OrthancPluginErrorCode (*OrthancPluginJobReleaseResources) (void* job); + typedef OrthancPluginErrorCode (*OrthancPluginJobReleaseResources) (void* job, + OrthancPluginJobReleaseReason reason); typedef OrthancPluginErrorCode (*OrthancPluginJobReset) (void* job); typedef OrthancPluginErrorCode (*OrthancPluginJobsUnserializer) (const char* jobType, const char* serialized);
--- a/UnitTestsSources/MultiThreadingTests.cpp Thu Sep 06 11:06:54 2018 +0200 +++ b/UnitTestsSources/MultiThreadingTests.cpp Thu Sep 06 12:32:02 2018 +0200 @@ -116,7 +116,7 @@ } } - virtual void ReleaseResources() + virtual void ReleaseResources(JobReleaseReason reason) { } @@ -162,7 +162,7 @@ { } - virtual void ReleaseResources() + virtual void ReleaseResources(JobReleaseReason reason) { }