refactor(Tasks): remove 'm_total_size' from ConcurrentTask

We can use the queues directly instead.

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow 2022-12-17 12:55:03 -03:00
parent c440f33122
commit 81fedbf03c
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
5 changed files with 12 additions and 15 deletions

View File

@ -123,7 +123,7 @@ auto NetJob::getFailedFiles() -> QList<QString>
void NetJob::updateState()
{
emit progress(m_done.count(), m_total_size);
emit progress(m_done.count(), totalSize());
setStatus(tr("Executing %1 task(s) (%2 out of %3 are done)")
.arg(QString::number(m_doing.count()), QString::number(m_done.count()), QString::number(m_total_size)));
.arg(QString::number(m_doing.count()), QString::number(m_done.count()), QString::number(totalSize())));
}

View File

@ -28,15 +28,12 @@ auto ConcurrentTask::getStepTotalProgress() const -> qint64
void ConcurrentTask::addTask(Task::Ptr task)
{
m_queue.append(task);
m_total_size += 1;
}
void ConcurrentTask::executeTask()
{
m_total_size = m_queue.size();
// Start the least amount of tasks needed, but at least one
int num_starts = std::max(1, std::min(m_total_max_size, m_total_size));
int num_starts = qMax(1, qMin(m_total_max_size, m_queue.size()));
for (int i = 0; i < num_starts; i++) {
QMetaObject::invokeMethod(this, &ConcurrentTask::startNext, Qt::QueuedConnection);
}
@ -83,8 +80,6 @@ void ConcurrentTask::clear()
m_progress = 0;
m_stepProgress = 0;
m_total_size = 0;
}
void ConcurrentTask::startNext()
@ -164,7 +159,7 @@ void ConcurrentTask::subTaskProgress(qint64 current, qint64 total)
void ConcurrentTask::updateState()
{
setProgress(m_done.count(), m_total_size);
setProgress(m_done.count(), totalSize());
setStatus(tr("Executing %1 task(s) (%2 out of %3 are done)")
.arg(QString::number(m_doing.count()), QString::number(m_done.count()), QString::number(m_total_size)));
.arg(QString::number(m_doing.count()), QString::number(m_done.count()), QString::number(totalSize())));
}

View File

@ -41,6 +41,9 @@ slots:
void subTaskProgress(qint64 current, qint64 total);
protected:
// NOTE: This is not thread-safe.
[[nodiscard]] unsigned int totalSize() const { return m_queue.size() + m_doing.size() + m_done.size(); }
void setStepStatus(QString status) { m_step_status = status; emit stepStatus(status); };
virtual void updateState();
@ -56,7 +59,6 @@ protected:
QHash<Task*, Task::Ptr> m_failed;
int m_total_max_size;
int m_total_size;
qint64 m_stepProgress = 0;
qint64 m_stepTotalProgress = 100;

View File

@ -22,6 +22,6 @@ void MultipleOptionsTask::startNext()
void MultipleOptionsTask::updateState()
{
setProgress(m_done.count(), m_total_size);
setStatus(tr("Attempting task %1 out of %2").arg(QString::number(m_doing.count() + m_done.count()), QString::number(m_total_size)));
setProgress(m_done.count(), totalSize());
setStatus(tr("Attempting task %1 out of %2").arg(QString::number(m_doing.count() + m_done.count()), QString::number(totalSize())));
}

View File

@ -17,6 +17,6 @@ void SequentialTask::startNext()
void SequentialTask::updateState()
{
setProgress(m_done.count(), m_total_size);
setStatus(tr("Executing task %1 out of %2").arg(QString::number(m_doing.count() + m_done.count()), QString::number(m_total_size)));
setProgress(m_done.count(), totalSize());
setStatus(tr("Executing task %1 out of %2").arg(QString::number(m_doing.count() + m_done.count()), QString::number(totalSize())));
}