fix shutdown

This commit is contained in:
Michael Zanetti 2019-11-15 23:54:40 +01:00
parent 0ce99fc127
commit 73812df269
2 changed files with 7 additions and 3 deletions

View File

@ -182,9 +182,10 @@ LogEngine::~LogEngine()
{ {
qWarning() << "Destroying logEngine"; qWarning() << "Destroying logEngine";
// Process the job queue before allowing to shut down // Process the job queue before allowing to shut down
while (!m_jobQueue.isEmpty() || !m_jobWatcher.isFinished()) { while (m_currentJob) {
qWarning() << "Waiting for job to finish..."; qWarning() << "Waiting for job to finish... (" << m_jobQueue.count() << "jobs left in queue)";
m_jobWatcher.waitForFinished(); m_jobWatcher.waitForFinished();
qApp->processEvents();
} }
qWarning() << "Done waiting"; qWarning() << "Done waiting";
qCDebug(dcLogEngine()) << "Closing Database"; qCDebug(dcLogEngine()) << "Closing Database";
@ -534,7 +535,7 @@ void LogEngine::processQueue()
return; return;
} }
if (!m_jobWatcher.isFinished()) { if (m_currentJob) {
return; return;
} }
@ -547,6 +548,7 @@ void LogEngine::processQueue()
} }
DatabaseJob *job = m_jobQueue.takeFirst(); DatabaseJob *job = m_jobQueue.takeFirst();
m_currentJob = job;
QFuture<DatabaseJob*> future = QtConcurrent::run([job](){ QFuture<DatabaseJob*> future = QtConcurrent::run([job](){
job->query().exec(); job->query().exec();
@ -561,6 +563,7 @@ void LogEngine::handleJobFinished()
DatabaseJob *job = m_jobWatcher.result(); DatabaseJob *job = m_jobWatcher.result();
job->finished(); job->finished();
job->deleteLater(); job->deleteLater();
m_currentJob = nullptr;
processQueue(); processQueue();
} }

View File

@ -96,6 +96,7 @@ private:
bool m_dbMalformed = false; bool m_dbMalformed = false;
QList<DatabaseJob*> m_jobQueue; QList<DatabaseJob*> m_jobQueue;
DatabaseJob *m_currentJob = nullptr;
QFutureWatcher<DatabaseJob*> m_jobWatcher; QFutureWatcher<DatabaseJob*> m_jobWatcher;
}; };