Mantid
Loading...
Searching...
No Matches
CatalogKeepAlive.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
10
11#include <Poco/Thread.h>
12
13namespace Mantid::ICat {
14DECLARE_ALGORITHM(CatalogKeepAlive)
15
16void CatalogKeepAlive::init() {
17 declareProperty("Session", "", "The session information of the catalog to use.");
18 declareProperty<int>("TimePeriod", 1200, "Frequency to refresh session in seconds. Default 1200 (20 minutes).",
20}
21
23 int timePeriod = getProperty("TimePeriod");
24 if (timePeriod <= 0)
25 throw std::runtime_error("TimePeriod must be greater than zero.");
26
27 Types::Core::DateAndTime lastTimeExecuted = Types::Core::DateAndTime::getCurrentTime();
28
29 // Keep going until cancelled
30 while (true) {
31 Poco::Thread::sleep(1000);
32
33 // Exit if the user presses cancel
34 this->interruption_point();
35
36 double secondsSinceExecuted =
37 Types::Core::DateAndTime::secondsFromDuration(Types::Core::DateAndTime::getCurrentTime() - lastTimeExecuted);
38
39 if (secondsSinceExecuted > timePeriod) {
40 API::CatalogManager::Instance().getCatalog(getPropertyValue("Session"))->keepAlive();
41 lastTimeExecuted = Types::Core::DateAndTime::getCurrentTime();
42 }
43 }
44}
45} // namespace Mantid::ICat
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
Definition: Algorithm.cpp:2026
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
void interruption_point()
This is called during long-running operations, and check if the algorithm has requested that it be ca...
Definition: Algorithm.cpp:1687
CatalogKeepAlive is responsible for keeping a catalog alive based on the session information.
void exec() override
Override algorithm execute method.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
@ Input
An input workspace.
Definition: Property.h:53