comparison Core/JobsEngine/JobsRegistry.cpp @ 2668:d26dd081df97 jobs

saving jobs engine on exit
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 08 Jun 2018 18:08:48 +0200
parents 5fa2f2ce74f0
children eaf10085ffa1
comparison
equal deleted inserted replaced
2667:5fa2f2ce74f0 2668:d26dd081df97
107 { 107 {
108 throw OrthancException(ErrorCode_NullPointer); 108 throw OrthancException(ErrorCode_NullPointer);
109 } 109 }
110 110
111 job->GetJobType(jobType_); 111 job->GetJobType(jobType_);
112 job->Start();
112 113
113 lastStatus_ = JobStatus(ErrorCode_Success, *job_); 114 lastStatus_ = JobStatus(ErrorCode_Success, *job_);
114 } 115 }
115 116
116 const std::string& GetId() const 117 const std::string& GetId() const
590 591
591 592
592 void JobsRegistry::SubmitInternal(std::string& id, 593 void JobsRegistry::SubmitInternal(std::string& id,
593 JobHandler* handlerRaw) 594 JobHandler* handlerRaw)
594 { 595 {
596 if (handlerRaw == NULL)
597 {
598 throw OrthancException(ErrorCode_NullPointer);
599 }
600
595 std::auto_ptr<JobHandler> handler(handlerRaw); 601 std::auto_ptr<JobHandler> handler(handlerRaw);
596 602
597 boost::mutex::scoped_lock lock(mutex_); 603 boost::mutex::scoped_lock lock(mutex_);
598 CheckInvariants(); 604 CheckInvariants();
599 605
600 id = handler->GetId(); 606 id = handler->GetId();
601 int priority = handler->GetPriority(); 607 int priority = handler->GetPriority();
602 608
603 pendingJobs_.push(handler.get()); 609 switch (handler->GetState())
604 pendingJobAvailable_.notify_one(); 610 {
611 case JobState_Pending:
612 case JobState_Retry:
613 case JobState_Running:
614 handler->SetState(JobState_Pending);
615 pendingJobs_.push(handler.get());
616 pendingJobAvailable_.notify_one();
617 break;
618
619 case JobState_Success:
620 SetCompletedJob(*handler, true);
621 break;
622
623 case JobState_Failure:
624 SetCompletedJob(*handler, false);
625 break;
626
627 case JobState_Paused:
628 break;
629
630 default:
631 LOG(ERROR) << "A job should not be loaded from state: "
632 << EnumerationToString(handler->GetState());
633 throw OrthancException(ErrorCode_InternalError);
634 }
605 635
606 jobsIndex_.insert(std::make_pair(id, handler.release())); 636 jobsIndex_.insert(std::make_pair(id, handler.release()));
607 637
608 LOG(INFO) << "New job submitted with priority " << priority << ": " << id; 638 LOG(INFO) << "New job submitted with priority " << priority << ": " << id;
609 639