Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-3.9] Feature/check server availibility everyminute #5928

Merged
merged 3 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/gui/accountstate.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/gui/accountstate.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/accountstate.cpp

File src/gui/accountstate.cpp (lines 566, 567): Code does not conform to Custom style guidelines.
* Copyright (C) by Daniel Molkentin <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -72,6 +72,10 @@
_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::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 @@ -215,6 +215,7 @@ protected Q_SLOTS:
private Q_SLOTS:

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

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

QTimer _checkServerAvailibilityTimer;

explicit AccountState() = default;

friend class ::FakeAccountState;
Expand Down
Loading