Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/private/TaskProcessing/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,19 @@ public function setTaskProgress(int $id, float $progress): bool {
}
$task->setStatus(Task::STATUS_RUNNING);
$task->setProgress($progress);
// Refine the expected completion time from the actual progress reported so far.
// We need a positive elapsed time and a positive progress to avoid divide-by-zero
// and the wildly unstable estimates produced when progress is still near zero.
$startedAt = $task->getStartedAt();
if ($startedAt !== null && $progress > 0.0) {
$elapsed = time() - $startedAt;
if ($elapsed > 0) {
$remainingSeconds = (int)ceil($elapsed * (1.0 - $progress) / $progress);
$completionExpectedAt = new \DateTime('now');
$completionExpectedAt->add(new \DateInterval('PT' . $remainingSeconds . 'S'));
$task->setCompletionExpectedAt($completionExpectedAt);
}
}
$taskEntity = \OC\TaskProcessing\Db\Task::fromPublicTask($task);
try {
$this->taskMapper->update($taskEntity);
Expand Down
Loading