Commit 697deda5 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit Committed by Kitware Robot

Merge topic '18511-fix-time-left'

ab38d3ca ensure time left doesn't reset on session reset
b1f2b79c "time left" timer not shown in all cases
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Mathieu Westphal's avatarMathieu Westphal <mathieu.westphal@kitware.com>
Merge-request: !2869
parents f3aea957 ab38d3ca
Pipeline #123170 failed with stage
in 0 seconds
......@@ -801,18 +801,13 @@ QVariant pqPipelineModel::data(const QModelIndex& idx, int role) const
if (server)
{
const pqServerResource& resource = server->getResource();
if (!resource.configuration().isNameDefault())
{
QString name = resource.configuration().name();
int time = server->getRemainingLifeTime();
QString timeLeft =
time > -1 ? QString(" (%1min left)").arg(QString::number(time)) : QString();
return QString("%1 (%2)%3").arg(name).arg(resource.configuration().URI()).arg(timeLeft);
}
else
{
return QVariant(resource.toURI());
}
const auto name = resource.configuration().isNameDefault()
? resource.toURI()
: resource.configuration().name();
int time = server->getRemainingLifeTime();
QString timeLeft =
time > -1 ? QString(" (%1min left)").arg(QString::number(time)) : QString();
return QString("%1 (%2)%3").arg(name).arg(resource.configuration().URI()).arg(timeLeft);
}
else if (source)
{
......
......@@ -78,6 +78,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <windows.h>
#endif
#include <chrono>
namespace pqObjectBuilderNS
{
static bool ContinueWaiting = true;
......@@ -734,6 +736,11 @@ pqServer* pqObjectBuilder::resetServer(pqServer* server)
{
Q_ASSERT(server);
// save the current remaining lifetime to restore it
// when we recreate the server following reset.
const int remainingLifetime = server->getRemainingLifeTime();
auto startTime = std::chrono::system_clock::now();
pqServerResource resource = server->getResource();
vtkSmartPointer<vtkSMSession> session = server->session();
vtkProcessModule* pm = vtkProcessModule::GetProcessModule();
......@@ -763,6 +770,11 @@ pqServer* pqObjectBuilder::resetServer(pqServer* server)
if (id != 0)
{
newServer = smModel->findServer(id);
auto endTime = std::chrono::system_clock::now();
auto deltaMinutes = std::chrono::duration_cast<std::chrono::minutes>(endTime - startTime);
newServer->setRemainingLifeTime(
remainingLifetime > 0 ? (remainingLifetime - deltaMinutes.count()) : remainingLifetime);
emit this->finishedAddingServer(newServer);
}
return newServer;
......
......@@ -78,10 +78,9 @@ public:
QTimer HeartbeatTimer;
QTimer ServerLifeTimeTimer;
// remaining time in minutes
int RemainingLifeTime;
int IdleServerMessageCounter;
// remaining time in minutes
int RemainingLifeTime{ -1 };
vtkNew<vtkEventQtSlotConnect> VTKConnect;
vtkWeakPointer<vtkSMCollaborationManager> CollaborationCommunicator;
......@@ -100,18 +99,14 @@ pqServer::pqServer(vtkIdType connectionID, vtkPVOptions* options, QObject* _pare
this->Session =
vtkSMSession::SafeDownCast(vtkProcessModule::GetProcessModule()->GetSession(connectionID));
QObject::connect(&this->Internals->ServerLifeTimeTimer, &QTimer::timeout, this,
&pqServer::updateRemainingLifeTime);
vtkPVServerInformation* serverInfo = this->getServerInformation();
if (this->isRemote() && serverInfo && serverInfo->GetTimeout() > 0)
{
this->Internals->RemainingLifeTime = serverInfo->GetTimeout();
QObject::connect(&this->Internals->ServerLifeTimeTimer, SIGNAL(timeout()), this,
SLOT(updateRemainingLifeTime()));
this->Internals->ServerLifeTimeTimer.start(60000); // trigger signal every minute
}
else
{
this->Internals->RemainingLifeTime = -1;
}
const int timeout = (this->isRemote() && serverInfo && serverInfo->GetTimeout() > 0)
? serverInfo->GetTimeout()
: -1;
this->setRemainingLifeTime(timeout);
QObject::connect(&this->Internals->HeartbeatTimer, SIGNAL(timeout()), this, SLOT(heartBeat()));
......@@ -178,6 +173,27 @@ void pqServer::setMonitorServerNotifications(bool val)
}
}
//-----------------------------------------------------------------------------
void pqServer::setRemainingLifeTime(int value)
{
auto& internals = (*this->Internals);
if (internals.RemainingLifeTime != value)
{
internals.RemainingLifeTime = value;
if (value > 0 && internals.ServerLifeTimeTimer.isActive() == false)
{
internals.ServerLifeTimeTimer.start(60000); // trigger signal every minute
}
else if (value <= 0)
{
internals.ServerLifeTimeTimer.stop();
}
// since RemainingLifeTime is used it labelling the server, fire nameChanged
// so pipeline browser can accurately indicate it.
emit this->nameChanged(this);
}
}
//-----------------------------------------------------------------------------
int pqServer::getRemainingLifeTime() const
{
......
......@@ -170,6 +170,11 @@ public:
*/
int getRemainingLifeTime() const;
/**
* Set the time (in minutes) remaining.
*/
void setRemainingLifeTime(int value);
signals:
/**
* Fired when the name of the proxy is changed.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment