-
Notifications
You must be signed in to change notification settings - Fork 122
/
CatalogKeepAlive.cpp
46 lines (37 loc) · 1.27 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
#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.");
Kernel::DateAndTime lastTimeExecuted = Kernel::DateAndTime::getCurrentTime();
// Keep going until cancelled
while (true) {
Poco::Thread::sleep(1000);
// Exit if the user presses cancel
this->interruption_point();
double secondsSinceExecuted = Kernel::DateAndTime::secondsFromDuration(
Kernel::DateAndTime::getCurrentTime() - lastTimeExecuted);
if (secondsSinceExecuted > timePeriod) {
API::CatalogManager::Instance()
.getCatalog(getPropertyValue("Session"))
->keepAlive();
lastTimeExecuted = Kernel::DateAndTime::getCurrentTime();
}
}
}
}
}