Mercurial > hg > orthanc
changeset 2671:06c0a6b8a871 jobs
new command-line argument: --no-jobs
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 11 Jun 2018 09:20:04 +0200 |
parents | c5646f766b3e |
children | 3efc44fac209 |
files | OrthancServer/ServerContext.cpp OrthancServer/ServerContext.h OrthancServer/main.cpp UnitTestsSources/MultiThreadingTests.cpp UnitTestsSources/ServerIndexTests.cpp |
diffstat | 5 files changed, 59 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/ServerContext.cpp Sat Jun 09 14:23:54 2018 +0200 +++ b/OrthancServer/ServerContext.cpp Mon Jun 11 09:20:04 2018 +0200 @@ -108,33 +108,42 @@ } - void ServerContext::SetupJobsEngine(bool unitTesting) + void ServerContext::SetupJobsEngine(bool unitTesting, + bool loadJobsFromDatabase) { jobsEngine_.SetWorkersCount(Configuration::GetGlobalUnsignedIntegerParameter("ConcurrentJobs", 2)); jobsEngine_.SetThreadSleep(unitTesting ? 20 : 200); - std::string serialized; - if (index_.LookupGlobalProperty(serialized, GlobalProperty_JobsRegistry)) + if (loadJobsFromDatabase) { - LOG(WARNING) << "Reloading the jobs from the last execution of Orthanc"; - OrthancJobUnserializer unserializer(*this); + std::string serialized; + if (index_.LookupGlobalProperty(serialized, GlobalProperty_JobsRegistry)) + { + LOG(WARNING) << "Reloading the jobs from the last execution of Orthanc"; + OrthancJobUnserializer unserializer(*this); - try - { - jobsEngine_.LoadRegistryFromString(unserializer, serialized); + try + { + jobsEngine_.LoadRegistryFromString(unserializer, serialized); + } + catch (OrthancException& e) + { + LOG(ERROR) << "Cannot unserialize the jobs engine: " << e.What(); + throw; + } } - catch (OrthancException& e) + else { - LOG(ERROR) << "Cannot unserialize the jobs engine: " << e.What(); - throw; + LOG(INFO) << "The last execution of Orthanc has archived no job"; } } else { - LOG(INFO) << "The last execution of Orthanc has archived no job"; - //jobsEngine_.GetRegistry().SetMaxCompleted // TODO + LOG(WARNING) << "Not reloading the jobs from the last execution of Orthanc"; } + //jobsEngine_.GetRegistry().SetMaxCompleted // TODO + jobsEngine_.Start(); } @@ -162,7 +171,8 @@ ServerContext::ServerContext(IDatabaseWrapper& database, IStorageArea& area, - bool unitTesting) : + bool unitTesting, + bool loadJobsFromDatabase) : index_(*this, database, (unitTesting ? 20 : 500)), area_(area), compressionEnabled_(false), @@ -179,7 +189,7 @@ { listeners_.push_back(ServerListener(lua_, "Lua")); - SetupJobsEngine(unitTesting); + SetupJobsEngine(unitTesting, loadJobsFromDatabase); changeThread_ = boost::thread(ChangeThread, this, (unitTesting ? 20 : 100)); }
--- a/OrthancServer/ServerContext.h Sat Jun 09 14:23:54 2018 +0200 +++ b/OrthancServer/ServerContext.h Mon Jun 11 09:20:04 2018 +0200 @@ -110,7 +110,8 @@ void ReadDicomAsJsonInternal(std::string& result, const std::string& instancePublicId); - void SetupJobsEngine(bool unitTesting); + void SetupJobsEngine(bool unitTesting, + bool loadJobsFromDatabase); void SaveJobsEngine(); @@ -164,7 +165,8 @@ ServerContext(IDatabaseWrapper& database, IStorageArea& area, - bool unitTesting); + bool unitTesting, + bool loadJobsFromDatabase); ~ServerContext();
--- a/OrthancServer/main.cpp Sat Jun 09 14:23:54 2018 +0200 +++ b/OrthancServer/main.cpp Mon Jun 11 09:20:04 2018 +0200 @@ -488,6 +488,8 @@ << " --upgrade\t\tallow Orthanc to upgrade the version of the" << std::endl << "\t\t\tdatabase (beware that the database will become" << std::endl << "\t\t\tincompatible with former versions of Orthanc)" << std::endl + << " --no-jobs\t\tDon't restart the jobs that were stored during" << std::endl + << "\t\t\tthe last execution of Orthanc" << std::endl << " --version\t\toutput version information and exit" << std::endl << std::endl << "Exit status:" << std::endl @@ -956,7 +958,8 @@ static bool ConfigureServerContext(IDatabaseWrapper& database, IStorageArea& storageArea, - OrthancPlugins *plugins) + OrthancPlugins *plugins, + bool loadJobsFromDatabase) { // These configuration options must be set before creating the // ServerContext, otherwise the possible Lua scripts will not be @@ -969,7 +972,7 @@ DicomUserConnection::SetDefaultTimeout(Configuration::GetGlobalUnsignedIntegerParameter("DicomScuTimeout", 10)); - ServerContext context(database, storageArea, false /* not running unit tests */); + ServerContext context(database, storageArea, false /* not running unit tests */, loadJobsFromDatabase); context.SetCompressionEnabled(Configuration::GetGlobalBoolParameter("StorageCompression", false)); context.SetStoreMD5ForAttachments(Configuration::GetGlobalBoolParameter("StoreMD5ForAttachments", true)); @@ -1040,7 +1043,8 @@ static bool ConfigureDatabase(IDatabaseWrapper& database, IStorageArea& storageArea, OrthancPlugins *plugins, - bool upgradeDatabase) + bool upgradeDatabase, + bool loadJobsFromDatabase) { database.Open(); @@ -1059,7 +1063,8 @@ throw OrthancException(ErrorCode_IncompatibleDatabaseVersion); } - bool success = ConfigureServerContext(database, storageArea, plugins); + bool success = ConfigureServerContext + (database, storageArea, plugins, loadJobsFromDatabase); database.Close(); @@ -1069,7 +1074,8 @@ static bool ConfigurePlugins(int argc, char* argv[], - bool upgradeDatabase) + bool upgradeDatabase, + bool loadJobsFromDatabase) { std::auto_ptr<IDatabaseWrapper> databasePtr; std::auto_ptr<IStorageArea> storage; @@ -1104,14 +1110,16 @@ assert(database != NULL); assert(storage.get() != NULL); - return ConfigureDatabase(*database, *storage, &plugins, upgradeDatabase); + return ConfigureDatabase(*database, *storage, &plugins, + upgradeDatabase, loadJobsFromDatabase); #elif ORTHANC_ENABLE_PLUGINS == 0 // The plugins are disabled databasePtr.reset(Configuration::CreateDatabaseWrapper()); storage.reset(Configuration::CreateStorageArea()); - return ConfigureDatabase(*databasePtr, *storage, NULL, upgradeDatabase); + return ConfigureDatabase(*databasePtr, *storage, NULL, + upgradeDatabase, loadJobsFromDatabase); #else # error The macro ORTHANC_ENABLE_PLUGINS must be set to 0 or 1 @@ -1121,9 +1129,10 @@ static bool StartOrthanc(int argc, char* argv[], - bool upgradeDatabase) + bool upgradeDatabase, + bool loadJobsFromDatabase) { - return ConfigurePlugins(argc, argv, upgradeDatabase); + return ConfigurePlugins(argc, argv, upgradeDatabase, loadJobsFromDatabase); } @@ -1140,6 +1149,7 @@ Logging::Initialize(); bool upgradeDatabase = false; + bool loadJobsFromDatabase = true; const char* configurationFile = NULL; @@ -1230,6 +1240,10 @@ { upgradeDatabase = true; } + else if (argument == "--no-jobs") + { + loadJobsFromDatabase = false; + } else if (boost::starts_with(argument, "--config=")) { // TODO WHAT IS THE ENCODING? @@ -1293,7 +1307,7 @@ { OrthancInitialize(configurationFile); - bool restart = StartOrthanc(argc, argv, upgradeDatabase); + bool restart = StartOrthanc(argc, argv, upgradeDatabase, loadJobsFromDatabase); if (restart) { OrthancFinalize();
--- a/UnitTestsSources/MultiThreadingTests.cpp Sat Jun 09 14:23:54 2018 +0200 +++ b/UnitTestsSources/MultiThreadingTests.cpp Mon Jun 11 09:20:04 2018 +0200 @@ -1184,7 +1184,8 @@ OrthancJobsSerialization() { db_.Open(); - context_.reset(new ServerContext(db_, storage_, true /* running unit tests */)); + context_.reset(new ServerContext(db_, storage_, true /* running unit tests */, + false /* don't reload jobs */)); } virtual ~OrthancJobsSerialization()
--- a/UnitTestsSources/ServerIndexTests.cpp Sat Jun 09 14:23:54 2018 +0200 +++ b/UnitTestsSources/ServerIndexTests.cpp Mon Jun 11 09:20:04 2018 +0200 @@ -675,7 +675,8 @@ FilesystemStorage storage(path); DatabaseWrapper db; // The SQLite DB is in memory db.Open(); - ServerContext context(db, storage, true /* running unit tests */); + ServerContext context(db, storage, true /* running unit tests */, + false /* don't reload jobs */); ServerIndex& index = context.GetIndex(); ASSERT_EQ(1u, index.IncrementGlobalSequence(GlobalProperty_AnonymizationSequence)); @@ -773,7 +774,8 @@ FilesystemStorage storage(path); DatabaseWrapper db; // The SQLite DB is in memory db.Open(); - ServerContext context(db, storage, true /* running unit tests */); + ServerContext context(db, storage, true /* running unit tests */, + false /* don't reload jobs */); ServerIndex& index = context.GetIndex(); index.SetMaximumStorageSize(10);