Skip to content

Commit

Permalink
✨ add faillock to daemon restarts
Browse files Browse the repository at this point in the history
  • Loading branch information
Reverier-Xu committed Nov 10, 2024
1 parent bc596df commit 7f4fe75
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion desktop/daemon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,18 @@ void Daemon::syncPool() {
}

void Daemon::heartbeat() {
if (m_daemon->state() != QProcess::Running) {
if (m_daemon->state() != QProcess::Running && m_faillock++ < 5) {
qWarning() << "Daemon is not running, try restart it.";
m_logs->appendLog(Log(QDateTime::currentDateTime().toString(Qt::ISODate), EventLevel::WARNING,
tr("Daemon is not running, try restart it."), "wsrx::desktop::connector"));
launch();
return;
} else if (m_faillock >= 5) {
qWarning() << "Daemon is not running, failed to restart it.";
m_logs->appendLog(Log(QDateTime::currentDateTime().toString(Qt::ISODate), EventLevel::ERROR,
tr("Daemon is not running and retries > 5, failed to restart it."),
"wsrx::desktop::connector"));
return;
}
auto request = QNetworkRequest(service("heartbeat"));
auto reply = m_network->get(request);
Expand Down
1 change: 1 addition & 0 deletions desktop/daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Daemon : public QObject {
QNetworkAccessManager* m_network;
QTimer* m_refreshTimer;
QTimer* m_heartbeatTimer;
int m_faillock = 0;

void syncPool();

Expand Down

0 comments on commit 7f4fe75

Please sign in to comment.