Simplify runtime startup polling, and increase retries to 30.

Ensure the splash screen is hidden before showing errors.
This commit is contained in:
Dave Page 2017-02-27 10:49:47 +00:00
parent 2ebd256307
commit 5a7a82b4e9
3 changed files with 6 additions and 49 deletions

View File

@ -101,8 +101,6 @@ BrowserWindow::BrowserWindow(QString url)
setCentralWidget(m_tabWidget);
connect(m_mainWebView, SIGNAL(loadFinished(bool)), SLOT(finishLoading(bool)));
#ifdef PGADMIN4_USE_WEBENGINE
// Register the slot when click on the URL link for QWebEnginePage
connect(m_mainWebView->page(), SIGNAL(createTabWindow(QWebEnginePage * &)),SLOT(createNewTabWindow(QWebEnginePage * &)));
@ -149,8 +147,6 @@ BrowserWindow::BrowserWindow(QString url)
m_last_open_folder_path = settings.value("Browser/LastSaveLocation", QDir::homePath()).toString();
// Display the app
m_initialLoad = true;
m_loadAttempt = 1;
m_mainWebView->setUrl(m_appServerUrl);
}
@ -267,43 +263,6 @@ void BrowserWindow::onMacPaste()
#endif
#endif
// Process loading finished signals from the web view.
void BrowserWindow::finishLoading(bool ok)
{
if (m_initialLoad && !ok)
{
// The load attempt failed. Try again up to 4 times with an
// incremental backoff.
if (m_loadAttempt < 5)
{
if (m_loadAttempt > 1)
{
qDebug() << "Initial connection failed. Retrying in" << m_loadAttempt << "seconds.";
m_mainWebView->setHtml(QString(tr("<p>Failed to connect to the pgAdmin application server. Retrying in %1 seconds, ") +
tr("or click <a href=\"%2\">here</a> to try again now.</p>")).arg(m_loadAttempt).arg(m_appServerUrl));
}
else
{
m_mainWebView->setHtml(QString(tr("<p>Connecting to the application server...</p>")));
}
pause(m_loadAttempt);
m_mainWebView->setUrl(m_appServerUrl);
m_loadAttempt++;
return;
}
else
{
qDebug() << "Initial connection failed after multiple attempts. Aborting.";
m_mainWebView->setHtml(QString(tr("<p>Failed to connect to the pgAdmin application server. ") +
tr("Click <a href=\"%1\">here</a> to try again.</p>")).arg(m_appServerUrl));
}
}
m_initialLoad = false;
}
// Check if Tab is already open with given URL name
int BrowserWindow::findURLTab(const QUrl &name)
{

View File

@ -48,7 +48,6 @@ protected:
void closeEvent(QCloseEvent *event);
protected slots:
void finishLoading(bool);
void urlLinkClicked(const QUrl &);
void closetabs();
void tabTitleChanged(const QString &);
@ -110,8 +109,6 @@ private:
QToolButton *m_toolBtnBack;
QToolButton *m_toolBtnForward;
bool m_initialLoad;
int m_loadAttempt;
QString m_downloadFilename;
int m_downloadStarted;
int m_downloadCancelled;

View File

@ -81,6 +81,8 @@ int main(int argc, char * argv[])
if (!server->Init())
{
splash->finish(NULL);
qDebug() << server->getError();
QString error = QString(QWidget::tr("An error occurred initialising the application server:\n\n%1")).arg(server->getError());
@ -141,11 +143,9 @@ int main(int argc, char * argv[])
QString appServerUrl = QString("http://localhost:%1/").arg(port);
// Now the server should be up, we'll attempt to connect and get a response.
// We'll retry in a loop a few time before aborting if necessary. The browser
// will also retry - that shouldn't (in theory) be necessary, but it won't
// hurt.
// We'll retry in a loop a few time before aborting if necessary.
int attempt = 0;
while (attempt++ < 10)
while (attempt++ < 30)
{
bool alive = PingServer(QUrl(appServerUrl));
@ -154,8 +154,9 @@ int main(int argc, char * argv[])
break;
}
if (attempt == 10)
if (attempt == 30)
{
splash->finish(NULL);
QString error(QWidget::tr("The application server could not be contacted."));
QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error);