-
Notifications
You must be signed in to change notification settings - Fork 122
/
CatalogKeepAlive.cpp
53 lines (44 loc) · 1.66 KB
/
CatalogKeepAlive.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidICat/CatalogKeepAlive.h"
#include "MantidAPI/CatalogManager.h"
#include "MantidKernel/DateAndTime.h"
#include <Poco/Thread.h>
namespace Mantid {
namespace ICat {
DECLARE_ALGORITHM(CatalogKeepAlive)
void CatalogKeepAlive::init() {
declareProperty("Session", "",
"The session information of the catalog to use.");
declareProperty<int>(
"TimePeriod", 1200,
"Frequency to refresh session in seconds. Default 1200 (20 minutes).",
Kernel::Direction::Input);
}
void CatalogKeepAlive::exec() {
int timePeriod = getProperty("TimePeriod");
if (timePeriod <= 0)
throw std::runtime_error("TimePeriod must be greater than zero.");
Types::Core::DateAndTime lastTimeExecuted =
Types::Core::DateAndTime::getCurrentTime();
// Keep going until cancelled
while (true) {
Poco::Thread::sleep(1000);
// Exit if the user presses cancel
this->interruption_point();
double secondsSinceExecuted = Types::Core::DateAndTime::secondsFromDuration(
Types::Core::DateAndTime::getCurrentTime() - lastTimeExecuted);
if (secondsSinceExecuted > timePeriod) {
API::CatalogManager::Instance()
.getCatalog(getPropertyValue("Session"))
->keepAlive();
lastTimeExecuted = Types::Core::DateAndTime::getCurrentTime();
}
}
}
} // namespace ICat
} // namespace Mantid