# HG changeset patch # User Sebastien Jodogne # Date 1525881374 -7200 # Node ID 3372c52553331d67e80bb0d47392c68d41b620e8 # Parent 2e879c796ec7c5bf283624a20d074f5cae46a6ea StoreScuJob, Orthanc Explorer for jobs diff -r 2e879c796ec7 -r 3372c5255333 Core/JobsEngine/IJob.h --- a/Core/JobsEngine/IJob.h Mon May 07 21:42:04 2018 +0200 +++ b/Core/JobsEngine/IJob.h Wed May 09 17:56:14 2018 +0200 @@ -56,6 +56,10 @@ virtual float GetProgress() = 0; - virtual void GetDescription(Json::Value& value) = 0; + virtual void GetJobType(std::string& target) = 0; + + virtual void GetPublicContent(Json::Value& value) = 0; + + virtual void GetInternalContent(Json::Value& value) = 0; }; } diff -r 2e879c796ec7 -r 3372c5255333 Core/JobsEngine/JobInfo.cpp --- a/Core/JobsEngine/JobInfo.cpp Mon May 07 21:42:04 2018 +0200 +++ b/Core/JobsEngine/JobInfo.cpp Wed May 09 17:56:14 2018 +0200 @@ -62,7 +62,8 @@ if (status_.GetProgress() > 0.01f && ms > 0.01f) { - float remaining = boost::math::llround(1.0f - status_.GetProgress()) * ms; + float ratio = static_cast(1.0 - status_.GetProgress()); + long long remaining = boost::math::llround(ratio * ms); eta_ = timestamp_ + boost::posix_time::milliseconds(remaining); hasEta_ = true; } @@ -115,7 +116,7 @@ } - void JobInfo::Format(Json::Value& target) const + void JobInfo::Serialize(Json::Value& target) const { target = Json::objectValue; target["ID"] = id_; @@ -125,9 +126,12 @@ target["State"] = EnumerationToString(state_); target["Timestamp"] = boost::posix_time::to_iso_string(timestamp_); target["CreationTime"] = boost::posix_time::to_iso_string(creationTime_); - target["Runtime"] = static_cast(runtime_.total_milliseconds()); + target["EffectiveRuntime"] = static_cast(runtime_.total_milliseconds()) / 1000.0; target["Progress"] = boost::math::iround(status_.GetProgress() * 100.0f); - target["Description"] = status_.GetDescription(); + + target["Type"] = status_.GetJobType(); + target["PublicContent"] = status_.GetPublicContent(); + target["InternalContent"] = status_.GetInternalContent(); if (HasEstimatedTimeOfArrival()) { diff -r 2e879c796ec7 -r 3372c5255333 Core/JobsEngine/JobInfo.h --- a/Core/JobsEngine/JobInfo.h Mon May 07 21:42:04 2018 +0200 +++ b/Core/JobsEngine/JobInfo.h Wed May 09 17:56:14 2018 +0200 @@ -115,6 +115,6 @@ return status_; } - void Format(Json::Value& target) const; + void Serialize(Json::Value& target) const; }; } diff -r 2e879c796ec7 -r 3372c5255333 Core/JobsEngine/JobStatus.cpp --- a/Core/JobsEngine/JobStatus.cpp Mon May 07 21:42:04 2018 +0200 +++ b/Core/JobsEngine/JobStatus.cpp Wed May 09 17:56:14 2018 +0200 @@ -39,7 +39,9 @@ JobStatus::JobStatus() : errorCode_(ErrorCode_InternalError), progress_(0), - description_(Json::objectValue) + jobType_("Invalid"), + publicContent_(Json::objectValue), + internalContent_(Json::objectValue) { } @@ -47,7 +49,9 @@ JobStatus::JobStatus(ErrorCode code, IJob& job) : errorCode_(code), - progress_(job.GetProgress()) + progress_(job.GetProgress()), + publicContent_(Json::objectValue), + internalContent_(Json::objectValue) { if (progress_ < 0) { @@ -59,6 +63,8 @@ progress_ = 1; } - job.GetDescription(description_); + job.GetJobType(jobType_); + job.GetPublicContent(publicContent_); + job.GetInternalContent(internalContent_); } } diff -r 2e879c796ec7 -r 3372c5255333 Core/JobsEngine/JobStatus.h --- a/Core/JobsEngine/JobStatus.h Mon May 07 21:42:04 2018 +0200 +++ b/Core/JobsEngine/JobStatus.h Wed May 09 17:56:14 2018 +0200 @@ -42,7 +42,9 @@ private: ErrorCode errorCode_; float progress_; - Json::Value description_; + std::string jobType_; + Json::Value publicContent_; + Json::Value internalContent_; public: JobStatus(); @@ -60,9 +62,19 @@ return progress_; } - const Json::Value& GetDescription() const + const std::string& GetJobType() const + { + return jobType_; + } + + const Json::Value& GetPublicContent() const { - return description_; + return publicContent_; + } + + const Json::Value& GetInternalContent() const + { + return internalContent_; } }; } diff -r 2e879c796ec7 -r 3372c5255333 Core/JobsEngine/JobsEngine.cpp --- a/Core/JobsEngine/JobsEngine.cpp Mon May 07 21:42:04 2018 +0200 +++ b/Core/JobsEngine/JobsEngine.cpp Wed May 09 17:56:14 2018 +0200 @@ -41,14 +41,18 @@ namespace Orthanc { + bool JobsEngine::IsRunning() + { + boost::mutex::scoped_lock lock(stateMutex_); + return (state_ == State_Running); + } + + bool JobsEngine::ExecuteStep(JobsRegistry::RunningJob& running, size_t workerIndex) { assert(running.IsValid()); - LOG(INFO) << "Executing job with priority " << running.GetPriority() - << " in worker thread " << workerIndex << ": " << running.GetId(); - if (running.IsPauseScheduled()) { running.GetJob().ReleaseResources(); @@ -94,10 +98,12 @@ switch (result->GetCode()) { case JobStepCode_Success: + running.GetJob().ReleaseResources(); running.MarkSuccess(); return false; case JobStepCode_Failure: + running.GetJob().ReleaseResources(); running.MarkFailure(); return false; @@ -119,19 +125,9 @@ { assert(engine != NULL); - for (;;) + while (engine->IsRunning()) { boost::this_thread::sleep(boost::posix_time::milliseconds(200)); - - { - boost::mutex::scoped_lock lock(engine->stateMutex_); - - if (engine->state_ != State_Running) - { - return; - } - } - engine->GetRegistry().ScheduleRetries(); } } @@ -144,22 +140,16 @@ LOG(INFO) << "Worker thread " << workerIndex << " has started"; - for (;;) + while (engine->IsRunning()) { - { - boost::mutex::scoped_lock lock(engine->stateMutex_); - - if (engine->state_ != State_Running) - { - return; - } - } - JobsRegistry::RunningJob running(engine->GetRegistry(), 100); if (running.IsValid()) { - for (;;) + LOG(INFO) << "Executing job with priority " << running.GetPriority() + << " in worker thread " << workerIndex << ": " << running.GetId(); + + while (engine->IsRunning()) { if (!engine->ExecuteStep(running, workerIndex)) { diff -r 2e879c796ec7 -r 3372c5255333 Core/JobsEngine/JobsEngine.h --- a/Core/JobsEngine/JobsEngine.h Mon May 07 21:42:04 2018 +0200 +++ b/Core/JobsEngine/JobsEngine.h Wed May 09 17:56:14 2018 +0200 @@ -56,6 +56,8 @@ boost::thread retryHandler_; std::vector workers_; + bool IsRunning(); + bool ExecuteStep(JobsRegistry::RunningJob& running, size_t workerIndex); diff -r 2e879c796ec7 -r 3372c5255333 Core/JobsEngine/JobsRegistry.cpp --- a/Core/JobsEngine/JobsRegistry.cpp Mon May 07 21:42:04 2018 +0200 +++ b/Core/JobsEngine/JobsRegistry.cpp Wed May 09 17:56:14 2018 +0200 @@ -520,7 +520,7 @@ } - void JobsRegistry::SetPriority(const std::string& id, + bool JobsRegistry::SetPriority(const std::string& id, int priority) { LOG(INFO) << "Changing priority to " << priority << " for job: " << id; @@ -533,6 +533,7 @@ if (found == jobsIndex_.end()) { LOG(WARNING) << "Unknown job: " << id; + return false; } else { @@ -553,13 +554,14 @@ copy.pop(); } } + + CheckInvariants(); + return true; } - - CheckInvariants(); } - void JobsRegistry::Pause(const std::string& id) + bool JobsRegistry::Pause(const std::string& id) { LOG(INFO) << "Pausing job: " << id; @@ -571,6 +573,7 @@ if (found == jobsIndex_.end()) { LOG(WARNING) << "Unknown job: " << id; + return false; } else { @@ -623,13 +626,14 @@ default: throw OrthancException(ErrorCode_InternalError); } + + CheckInvariants(); + return true; } - - CheckInvariants(); } - void JobsRegistry::Resume(const std::string& id) + bool JobsRegistry::Resume(const std::string& id) { LOG(INFO) << "Resuming job: " << id; @@ -641,23 +645,25 @@ if (found == jobsIndex_.end()) { LOG(WARNING) << "Unknown job: " << id; + return false; } else if (found->second->GetState() != JobState_Paused) { LOG(WARNING) << "Cannot resume a job that is not paused: " << id; + return false; } else { found->second->SetState(JobState_Pending); pendingJobs_.push(found->second); pendingJobAvailable_.notify_one(); + CheckInvariants(); + return true; } - - CheckInvariants(); } - void JobsRegistry::Resubmit(const std::string& id) + bool JobsRegistry::Resubmit(const std::string& id) { LOG(INFO) << "Resubmitting failed job: " << id; @@ -669,10 +675,12 @@ if (found == jobsIndex_.end()) { LOG(WARNING) << "Unknown job: " << id; + return false; } else if (found->second->GetState() != JobState_Failure) { LOG(WARNING) << "Cannot resubmit a job that has not failed: " << id; + return false; } else { @@ -693,9 +701,10 @@ found->second->SetState(JobState_Pending); pendingJobs_.push(found->second); pendingJobAvailable_.notify_one(); + + CheckInvariants(); + return true; } - - CheckInvariants(); } diff -r 2e879c796ec7 -r 3372c5255333 Core/JobsEngine/JobsRegistry.h --- a/Core/JobsEngine/JobsRegistry.h Mon May 07 21:42:04 2018 +0200 +++ b/Core/JobsEngine/JobsRegistry.h Wed May 09 17:56:14 2018 +0200 @@ -130,14 +130,14 @@ bool SubmitAndWait(IJob* job, // Takes ownership int priority); - void SetPriority(const std::string& id, + bool SetPriority(const std::string& id, int priority); - void Pause(const std::string& id); + bool Pause(const std::string& id); - void Resume(const std::string& id); + bool Resume(const std::string& id); - void Resubmit(const std::string& id); + bool Resubmit(const std::string& id); void ScheduleRetries(); diff -r 2e879c796ec7 -r 3372c5255333 OrthancExplorer/explorer.html --- a/OrthancExplorer/explorer.html Mon May 07 21:42:04 2018 +0200 +++ b/OrthancExplorer/explorer.html Wed May 09 17:56:14 2018 +0200 @@ -37,7 +37,10 @@

Find a patient

- Plugins +
+ Plugins + Jobs +
Upload Query/Retrieve @@ -418,6 +421,43 @@
+ +
+
+

Jobs

+ Patients +
+
+
    +
+
+
+ +
+
+

Job

+
+ Patients + Jobs +
+
+
+
    +
+ +
+
+
+ + + + + +
+
+
+
+