Mercurial > hg > orthanc
comparison Core/JobsEngine/JobsRegistry.cpp @ 2570:2e879c796ec7 jobs
JobsRegistry::SubmitAndWait(), StoreScuJob
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 07 May 2018 21:42:04 +0200 |
parents | 2af17cd5eb1f |
children | 3372c5255333 |
comparison
equal
deleted
inserted
replaced
2569:2af17cd5eb1f | 2570:2e879c796ec7 |
---|---|
90 { | 90 { |
91 throw OrthancException(ErrorCode_NullPointer); | 91 throw OrthancException(ErrorCode_NullPointer); |
92 } | 92 } |
93 | 93 |
94 lastStatus_ = JobStatus(ErrorCode_Success, *job); | 94 lastStatus_ = JobStatus(ErrorCode_Success, *job); |
95 job->Start(); | |
95 } | 96 } |
96 | 97 |
97 const std::string& GetId() const | 98 const std::string& GetId() const |
98 { | 99 { |
99 return id_; | 100 return id_; |
346 job.SetState(success ? JobState_Success : JobState_Failure); | 347 job.SetState(success ? JobState_Success : JobState_Failure); |
347 | 348 |
348 completedJobs_.push_back(&job); | 349 completedJobs_.push_back(&job); |
349 ForgetOldCompletedJobs(); | 350 ForgetOldCompletedJobs(); |
350 | 351 |
352 someJobComplete_.notify_all(); | |
353 | |
351 CheckInvariants(); | 354 CheckInvariants(); |
352 } | 355 } |
353 | 356 |
354 | 357 |
355 void JobsRegistry::MarkRunningAsRetry(JobHandler& job, | 358 void JobsRegistry::MarkRunningAsRetry(JobHandler& job, |
380 | 383 |
381 CheckInvariants(); | 384 CheckInvariants(); |
382 } | 385 } |
383 | 386 |
384 | 387 |
388 bool JobsRegistry::GetStateInternal(JobState& state, | |
389 const std::string& id) | |
390 { | |
391 CheckInvariants(); | |
392 | |
393 JobsIndex::const_iterator it = jobsIndex_.find(id); | |
394 if (it == jobsIndex_.end()) | |
395 { | |
396 return false; | |
397 } | |
398 else | |
399 { | |
400 state = it->second->GetState(); | |
401 return true; | |
402 } | |
403 } | |
404 | |
405 | |
385 JobsRegistry::~JobsRegistry() | 406 JobsRegistry::~JobsRegistry() |
386 { | 407 { |
387 for (JobsIndex::iterator it = jobsIndex_.begin(); it != jobsIndex_.end(); ++it) | 408 for (JobsIndex::iterator it = jobsIndex_.begin(); it != jobsIndex_.end(); ++it) |
388 { | 409 { |
389 assert(it->second != NULL); | 410 assert(it->second != NULL); |
472 std::string id; | 493 std::string id; |
473 Submit(id, job, priority); | 494 Submit(id, job, priority); |
474 } | 495 } |
475 | 496 |
476 | 497 |
498 bool JobsRegistry::SubmitAndWait(IJob* job, // Takes ownership | |
499 int priority) | |
500 { | |
501 std::string id; | |
502 Submit(id, job, priority); | |
503 | |
504 printf(">> %s\n", id.c_str()); fflush(stdout); | |
505 | |
506 JobState state; | |
507 | |
508 { | |
509 boost::mutex::scoped_lock lock(mutex_); | |
510 | |
511 while (GetStateInternal(state, id) && | |
512 state != JobState_Success && | |
513 state != JobState_Failure) | |
514 { | |
515 someJobComplete_.wait(lock); | |
516 } | |
517 } | |
518 | |
519 return (state == JobState_Success); | |
520 } | |
521 | |
522 | |
477 void JobsRegistry::SetPriority(const std::string& id, | 523 void JobsRegistry::SetPriority(const std::string& id, |
478 int priority) | 524 int priority) |
479 { | 525 { |
480 LOG(INFO) << "Changing priority to " << priority << " for job: " << id; | 526 LOG(INFO) << "Changing priority to " << priority << " for job: " << id; |
481 | 527 |
685 | 731 |
686 bool JobsRegistry::GetState(JobState& state, | 732 bool JobsRegistry::GetState(JobState& state, |
687 const std::string& id) | 733 const std::string& id) |
688 { | 734 { |
689 boost::mutex::scoped_lock lock(mutex_); | 735 boost::mutex::scoped_lock lock(mutex_); |
690 CheckInvariants(); | 736 return GetStateInternal(state, id); |
691 | |
692 JobsIndex::const_iterator it = jobsIndex_.find(id); | |
693 if (it == jobsIndex_.end()) | |
694 { | |
695 return false; | |
696 } | |
697 else | |
698 { | |
699 state = it->second->GetState(); | |
700 return true; | |
701 } | |
702 } | 737 } |
703 | 738 |
704 | 739 |
705 JobsRegistry::RunningJob::RunningJob(JobsRegistry& registry, | 740 JobsRegistry::RunningJob::RunningJob(JobsRegistry& registry, |
706 unsigned int timeout) : | 741 unsigned int timeout) : |