Skip to content

Commit

Permalink
Merge pull request #5621 from nextcloud/feature/check-server-availibi…
Browse files Browse the repository at this point in the history
…lity-everyminute

Feature/check server availibility everyminute
  • Loading branch information
mgallien authored Jul 26, 2023
2 parents 16eaa35 + 2cb03e4 commit 10b623e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/gui/accountstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ AccountState::AccountState(AccountPtr account)
_checkConnectionTimer.setInterval(ConnectionValidator::DefaultCallingIntervalMsec);
_checkConnectionTimer.start();

connect(&_checkServerAvailibilityTimer, &QTimer::timeout, this, &AccountState::slotCheckServerAvailibility);
_checkServerAvailibilityTimer.setInterval(ConnectionValidator::DefaultCallingIntervalMsec);
_checkServerAvailibilityTimer.start();

QTimer::singleShot(0, this, &AccountState::slotCheckConnection);
}

Expand Down Expand Up @@ -557,6 +561,28 @@ void AccountState::slotCheckConnection()
}
}

void AccountState::slotCheckServerAvailibility()
{
if (state() == AccountState::Connected
|| state() == AccountState::SignedOut
|| state() == AccountState::MaintenanceMode
|| state() == AccountState::AskingCredentials) {
qCInfo(lcAccountState) << "Skipping server availibility check for account" << _account->davUser() << "with state" << state();
return;
}
qCInfo(lcAccountState) << "Checking server availibility for account" << _account->davUser();
const auto serverAvailibilityUrl = Utility::concatUrlPath(_account->url(), QLatin1String("/index.php/204"));
auto checkServerAvailibilityJob = _account->sendRequest(QByteArrayLiteral("GET"), serverAvailibilityUrl);
connect(checkServerAvailibilityJob, &SimpleNetworkJob::finishedSignal, this, [this](QNetworkReply *reply) {
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) == 204) {
qCInfo(lcAccountState) << "Server is now available for account" << _account->davUser();
_lastCheckConnectionTimer.invalidate();
resetRetryCount();
QMetaObject::invokeMethod(this, &AccountState::slotCheckConnection, Qt::QueuedConnection);
}
});
}

void AccountState::slotPushNotificationsReady()
{
if (state() != AccountState::State::Connected) {
Expand Down
3 changes: 3 additions & 0 deletions src/gui/accountstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ protected Q_SLOTS:
private Q_SLOTS:

void slotCheckConnection();
void slotCheckServerAvailibility();
void slotPushNotificationsReady();
void slotServerUserStatusChanged();

Expand Down Expand Up @@ -261,6 +262,8 @@ private Q_SLOTS:
QTimer _checkConnectionTimer;
QElapsedTimer _lastCheckConnectionTimer;

QTimer _checkServerAvailibilityTimer;

explicit AccountState() = default;

friend class ::FakeAccountState;
Expand Down

0 comments on commit 10b623e

Please sign in to comment.