mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2024-11-24 17:50:20 -06:00
Handle slow startup of the web server.
If the web server is slow to start, we may need to retry the initial page load. Implement a retry system that will retry the initial load 4 times, after 1, 2, 3 and 4 seconds, before giving up and leaving the user with an error message and a link to retry manually.
This commit is contained in:
parent
7fd90ac10f
commit
9080a782d5
@ -30,6 +30,7 @@
|
||||
// App headers
|
||||
#include "BrowserWindow.h"
|
||||
|
||||
|
||||
// Constructor
|
||||
BrowserWindow::BrowserWindow()
|
||||
{
|
||||
@ -39,11 +40,15 @@ BrowserWindow::BrowserWindow()
|
||||
// Create the WebKit control
|
||||
webView = new QWebView(this);
|
||||
setCentralWidget(webView);
|
||||
connect(webView, SIGNAL(loadFinished(bool)), SLOT(finishLoading(bool)));
|
||||
|
||||
// Display the app
|
||||
webView->setUrl(QString("http://127.0.0.1:8080"));
|
||||
m_initialload = true;
|
||||
m_loadattempt = 1;
|
||||
webView->setUrl(PGA_SERVER_URL);
|
||||
}
|
||||
|
||||
|
||||
// Create the actions for the window
|
||||
void BrowserWindow::createActions()
|
||||
{
|
||||
@ -65,6 +70,7 @@ void BrowserWindow::createActions()
|
||||
connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
|
||||
}
|
||||
|
||||
|
||||
// Create the application menus
|
||||
void BrowserWindow::createMenus()
|
||||
{
|
||||
@ -81,12 +87,54 @@ void BrowserWindow::createMenus()
|
||||
helpMenu->addAction(aboutAction);
|
||||
}
|
||||
|
||||
|
||||
// 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)
|
||||
{
|
||||
qDebug() << "Initial load failed. Retrying in" << m_loadattempt << "seconds.";
|
||||
webView->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(PGA_SERVER_URL));
|
||||
|
||||
pause(m_loadattempt);
|
||||
webView->setUrl(PGA_SERVER_URL);
|
||||
m_loadattempt++;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Initial page load failed after multiple attempts. Aborting.";
|
||||
webView->setHtml(QString(tr("<p>Failed to connect to the pgAdmin application server. ") +
|
||||
tr("Click <a href=\"%1\">here</a> to try again.</p>")).arg(PGA_SERVER_URL));
|
||||
}
|
||||
}
|
||||
|
||||
m_initialload = false;
|
||||
}
|
||||
|
||||
|
||||
// Pause for n seconds, without freezing the UI.
|
||||
void BrowserWindow::pause(int seconds)
|
||||
{
|
||||
QTime dieTime = QTime::currentTime().addSecs(seconds);
|
||||
|
||||
while (QTime::currentTime() < dieTime)
|
||||
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
|
||||
}
|
||||
|
||||
|
||||
// Display the about box
|
||||
void BrowserWindow::about()
|
||||
{
|
||||
QMessageBox::about(this, tr("About pgAdmin 4"), tr("pgAdmin 4 - PostgreSQL Tools"));
|
||||
}
|
||||
|
||||
|
||||
// Open an arbitrary URL
|
||||
void BrowserWindow::openUrl()
|
||||
{
|
||||
|
@ -36,6 +36,9 @@ class BrowserWindow : public QMainWindow
|
||||
public:
|
||||
BrowserWindow();
|
||||
|
||||
protected slots:
|
||||
void finishLoading(bool);
|
||||
|
||||
private slots:
|
||||
void openUrl();
|
||||
void about();
|
||||
@ -48,8 +51,12 @@ private:
|
||||
QAction *exitAction;
|
||||
QAction *aboutAction;
|
||||
|
||||
bool m_initialload;
|
||||
int m_loadattempt;
|
||||
|
||||
void createActions();
|
||||
void createMenus();
|
||||
void pause(int seconds = 1);
|
||||
};
|
||||
|
||||
#endif // BROWSERWINDOW_H
|
||||
|
@ -25,7 +25,7 @@
|
||||
Server::Server()
|
||||
{
|
||||
// Initialise Python
|
||||
Py_SetProgramName(PGA_APPNAME.toUtf8().data());
|
||||
Py_SetProgramName(PGA_APP_NAME.toUtf8().data());
|
||||
Py_Initialize();
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,10 @@
|
||||
#include <QApplication>
|
||||
#endif
|
||||
|
||||
// char *PGA_APPNAME = "pgAdmin 4";
|
||||
const QString PGA_APPNAME = QString("pgAdmin 4");
|
||||
// Application name
|
||||
const QString PGA_APP_NAME = QString("pgAdmin 4");
|
||||
|
||||
// Server URL
|
||||
const QString PGA_SERVER_URL = QString("http://127.0.0.1:8080");
|
||||
|
||||
#endif // PGADMIN4_H
|
||||
|
Loading…
Reference in New Issue
Block a user