GH-1927 Add more specific task status logging
* Tasks are now described by class name and object name (or memory address). * Tasks starts are logged. * Aborted tasks are now treated just as the other cases.
This commit is contained in:
@ -41,31 +41,79 @@ void Task::start()
|
||||
{
|
||||
m_running = true;
|
||||
emit started();
|
||||
qDebug() << "Task" << describe() << "started";
|
||||
executeTask();
|
||||
}
|
||||
|
||||
void Task::emitFailed(QString reason)
|
||||
{
|
||||
// Don't fail twice.
|
||||
if (!m_running)
|
||||
{
|
||||
qCritical() << "Task" << describe() << "failed while not running!!!!: " << reason;
|
||||
return;
|
||||
}
|
||||
m_running = false;
|
||||
m_finished = true;
|
||||
m_succeeded = false;
|
||||
m_failReason = reason;
|
||||
qCritical() << "Task failed: " << reason;
|
||||
qCritical() << "Task" << describe() << "failed: " << reason;
|
||||
emit failed(reason);
|
||||
emit finished();
|
||||
}
|
||||
|
||||
void Task::emitAborted()
|
||||
{
|
||||
// Don't abort twice.
|
||||
if (!m_running)
|
||||
{
|
||||
qCritical() << "Task" << describe() << "aborted while not running!!!!";
|
||||
return;
|
||||
}
|
||||
m_running = false;
|
||||
m_finished = true;
|
||||
m_succeeded = false;
|
||||
m_failReason = "Aborted.";
|
||||
qDebug() << "Task" << describe() << "aborted.";
|
||||
emit failed(m_failReason);
|
||||
emit finished();
|
||||
}
|
||||
|
||||
void Task::emitSucceeded()
|
||||
{
|
||||
if (!m_running) { return; } // Don't succeed twice.
|
||||
// Don't succeed twice.
|
||||
if (!m_running)
|
||||
{
|
||||
qCritical() << "Task" << describe() << "succeeded while not running!!!!";
|
||||
return;
|
||||
}
|
||||
m_running = false;
|
||||
m_finished = true;
|
||||
m_succeeded = true;
|
||||
qDebug() << "Task succeeded";
|
||||
qDebug() << "Task" << describe() << "succeeded";
|
||||
emit succeeded();
|
||||
emit finished();
|
||||
}
|
||||
|
||||
QString Task::describe()
|
||||
{
|
||||
QString outStr;
|
||||
QTextStream out(&outStr);
|
||||
out << metaObject()->className() << QChar('(');
|
||||
auto name = objectName();
|
||||
if(name.isEmpty())
|
||||
{
|
||||
out << QString("0x%1").arg((quintptr)this, 0, 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
out << name;
|
||||
}
|
||||
out << QChar(')');
|
||||
out.flush();
|
||||
return outStr;
|
||||
}
|
||||
|
||||
bool Task::isRunning() const
|
||||
{
|
||||
return m_running;
|
||||
|
@ -54,6 +54,9 @@ public:
|
||||
return m_progressTotal;
|
||||
}
|
||||
|
||||
private:
|
||||
QString describe();
|
||||
|
||||
signals:
|
||||
void started();
|
||||
void progress(qint64 current, qint64 total);
|
||||
@ -71,6 +74,7 @@ protected:
|
||||
|
||||
protected slots:
|
||||
virtual void emitSucceeded();
|
||||
virtual void emitAborted();
|
||||
virtual void emitFailed(QString reason);
|
||||
|
||||
public slots:
|
||||
|
Reference in New Issue
Block a user