comparison Core/JobsEngine/JobsRegistry.cpp @ 2573:3372c5255333 jobs

StoreScuJob, Orthanc Explorer for jobs
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 09 May 2018 17:56:14 +0200
parents 2e879c796ec7
children 8da2cffc2378
comparison
equal deleted inserted replaced
2570:2e879c796ec7 2573:3372c5255333
518 518
519 return (state == JobState_Success); 519 return (state == JobState_Success);
520 } 520 }
521 521
522 522
523 void JobsRegistry::SetPriority(const std::string& id, 523 bool JobsRegistry::SetPriority(const std::string& id,
524 int priority) 524 int priority)
525 { 525 {
526 LOG(INFO) << "Changing priority to " << priority << " for job: " << id; 526 LOG(INFO) << "Changing priority to " << priority << " for job: " << id;
527 527
528 boost::mutex::scoped_lock lock(mutex_); 528 boost::mutex::scoped_lock lock(mutex_);
531 JobsIndex::iterator found = jobsIndex_.find(id); 531 JobsIndex::iterator found = jobsIndex_.find(id);
532 532
533 if (found == jobsIndex_.end()) 533 if (found == jobsIndex_.end())
534 { 534 {
535 LOG(WARNING) << "Unknown job: " << id; 535 LOG(WARNING) << "Unknown job: " << id;
536 return false;
536 } 537 }
537 else 538 else
538 { 539 {
539 found->second->SetPriority(priority); 540 found->second->SetPriority(priority);
540 541
551 { 552 {
552 pendingJobs_.push(copy.top()); 553 pendingJobs_.push(copy.top());
553 copy.pop(); 554 copy.pop();
554 } 555 }
555 } 556 }
556 } 557
557 558 CheckInvariants();
558 CheckInvariants(); 559 return true;
559 } 560 }
560 561 }
561 562
562 void JobsRegistry::Pause(const std::string& id) 563
564 bool JobsRegistry::Pause(const std::string& id)
563 { 565 {
564 LOG(INFO) << "Pausing job: " << id; 566 LOG(INFO) << "Pausing job: " << id;
565 567
566 boost::mutex::scoped_lock lock(mutex_); 568 boost::mutex::scoped_lock lock(mutex_);
567 CheckInvariants(); 569 CheckInvariants();
569 JobsIndex::iterator found = jobsIndex_.find(id); 571 JobsIndex::iterator found = jobsIndex_.find(id);
570 572
571 if (found == jobsIndex_.end()) 573 if (found == jobsIndex_.end())
572 { 574 {
573 LOG(WARNING) << "Unknown job: " << id; 575 LOG(WARNING) << "Unknown job: " << id;
576 return false;
574 } 577 }
575 else 578 else
576 { 579 {
577 switch (found->second->GetState()) 580 switch (found->second->GetState())
578 { 581 {
621 break; 624 break;
622 625
623 default: 626 default:
624 throw OrthancException(ErrorCode_InternalError); 627 throw OrthancException(ErrorCode_InternalError);
625 } 628 }
626 } 629
627 630 CheckInvariants();
628 CheckInvariants(); 631 return true;
629 } 632 }
630 633 }
631 634
632 void JobsRegistry::Resume(const std::string& id) 635
636 bool JobsRegistry::Resume(const std::string& id)
633 { 637 {
634 LOG(INFO) << "Resuming job: " << id; 638 LOG(INFO) << "Resuming job: " << id;
635 639
636 boost::mutex::scoped_lock lock(mutex_); 640 boost::mutex::scoped_lock lock(mutex_);
637 CheckInvariants(); 641 CheckInvariants();
639 JobsIndex::iterator found = jobsIndex_.find(id); 643 JobsIndex::iterator found = jobsIndex_.find(id);
640 644
641 if (found == jobsIndex_.end()) 645 if (found == jobsIndex_.end())
642 { 646 {
643 LOG(WARNING) << "Unknown job: " << id; 647 LOG(WARNING) << "Unknown job: " << id;
648 return false;
644 } 649 }
645 else if (found->second->GetState() != JobState_Paused) 650 else if (found->second->GetState() != JobState_Paused)
646 { 651 {
647 LOG(WARNING) << "Cannot resume a job that is not paused: " << id; 652 LOG(WARNING) << "Cannot resume a job that is not paused: " << id;
653 return false;
648 } 654 }
649 else 655 else
650 { 656 {
651 found->second->SetState(JobState_Pending); 657 found->second->SetState(JobState_Pending);
652 pendingJobs_.push(found->second); 658 pendingJobs_.push(found->second);
653 pendingJobAvailable_.notify_one(); 659 pendingJobAvailable_.notify_one();
654 } 660 CheckInvariants();
655 661 return true;
656 CheckInvariants(); 662 }
657 } 663 }
658 664
659 665
660 void JobsRegistry::Resubmit(const std::string& id) 666 bool JobsRegistry::Resubmit(const std::string& id)
661 { 667 {
662 LOG(INFO) << "Resubmitting failed job: " << id; 668 LOG(INFO) << "Resubmitting failed job: " << id;
663 669
664 boost::mutex::scoped_lock lock(mutex_); 670 boost::mutex::scoped_lock lock(mutex_);
665 CheckInvariants(); 671 CheckInvariants();
667 JobsIndex::iterator found = jobsIndex_.find(id); 673 JobsIndex::iterator found = jobsIndex_.find(id);
668 674
669 if (found == jobsIndex_.end()) 675 if (found == jobsIndex_.end())
670 { 676 {
671 LOG(WARNING) << "Unknown job: " << id; 677 LOG(WARNING) << "Unknown job: " << id;
678 return false;
672 } 679 }
673 else if (found->second->GetState() != JobState_Failure) 680 else if (found->second->GetState() != JobState_Failure)
674 { 681 {
675 LOG(WARNING) << "Cannot resubmit a job that has not failed: " << id; 682 LOG(WARNING) << "Cannot resubmit a job that has not failed: " << id;
683 return false;
676 } 684 }
677 else 685 else
678 { 686 {
679 bool ok = false; 687 bool ok = false;
680 for (CompletedJobs::iterator it = completedJobs_.begin(); 688 for (CompletedJobs::iterator it = completedJobs_.begin();
691 assert(ok); 699 assert(ok);
692 700
693 found->second->SetState(JobState_Pending); 701 found->second->SetState(JobState_Pending);
694 pendingJobs_.push(found->second); 702 pendingJobs_.push(found->second);
695 pendingJobAvailable_.notify_one(); 703 pendingJobAvailable_.notify_one();
696 } 704
697 705 CheckInvariants();
698 CheckInvariants(); 706 return true;
707 }
699 } 708 }
700 709
701 710
702 void JobsRegistry::ScheduleRetries() 711 void JobsRegistry::ScheduleRetries()
703 { 712 {