File tree Expand file tree Collapse file tree
lib/private/TaskProcessing Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1254,7 +1254,22 @@ public function setTaskProgress(int $id, float $progress): bool {
12541254 $ task ->setStartedAt (time ());
12551255 }
12561256 $ task ->setStatus (Task::STATUS_RUNNING );
1257- $ task ->setProgress ($ progress );
1257+ if ($ progress >= 0 && $ progress <= 1.0 ) {
1258+ $ task ->setProgress ($ progress );
1259+ // Refine the expected completion time from the actual progress reported so far.
1260+ // We need a positive elapsed time and a positive progress to avoid divide-by-zero
1261+ // and the wildly unstable estimates produced when progress is still near zero.
1262+ $ startedAt = $ task ->getStartedAt ();
1263+ if ($ startedAt !== null && $ progress > 0.0 ) {
1264+ $ elapsed = time () - $ startedAt ;
1265+ if ($ elapsed > 0 ) {
1266+ $ remainingSeconds = (int )ceil ($ elapsed * (1.0 - $ progress ) / $ progress );
1267+ $ completionExpectedAt = new \DateTime ('now ' );
1268+ $ completionExpectedAt ->add (new \DateInterval ('PT ' . $ remainingSeconds . 'S ' ));
1269+ $ task ->setCompletionExpectedAt ($ completionExpectedAt );
1270+ }
1271+ }
1272+ }
12581273 $ taskEntity = \OC \TaskProcessing \Db \Task::fromPublicTask ($ task );
12591274 try {
12601275 $ this ->taskMapper ->update ($ taskEntity );
You can’t perform that action at this time.
0 commit comments