Update information associated with a task. Args: task_id (TaskID): Task id (returned by add_task). total (float, optional): Updates task.total if not None. completed (float, optional): Updates task.completed if not None. advance (float, option
(
self,
task_id: TaskID,
*,
total: Optional[float] = None,
completed: Optional[float] = None,
advance: Optional[float] = None,
description: Optional[str] = None,
visible: Optional[bool] = None,
refresh: bool = False,
**fields: Any,
)
| 1415 | task.stop_time = current_time |
| 1416 | |
| 1417 | def update( |
| 1418 | self, |
| 1419 | task_id: TaskID, |
| 1420 | *, |
| 1421 | total: Optional[float] = None, |
| 1422 | completed: Optional[float] = None, |
| 1423 | advance: Optional[float] = None, |
| 1424 | description: Optional[str] = None, |
| 1425 | visible: Optional[bool] = None, |
| 1426 | refresh: bool = False, |
| 1427 | **fields: Any, |
| 1428 | ) -> None: |
| 1429 | """Update information associated with a task. |
| 1430 | |
| 1431 | Args: |
| 1432 | task_id (TaskID): Task id (returned by add_task). |
| 1433 | total (float, optional): Updates task.total if not None. |
| 1434 | completed (float, optional): Updates task.completed if not None. |
| 1435 | advance (float, optional): Add a value to task.completed if not None. |
| 1436 | description (str, optional): Change task description if not None. |
| 1437 | visible (bool, optional): Set visible flag if not None. |
| 1438 | refresh (bool): Force a refresh of progress information. Default is False. |
| 1439 | **fields (Any): Additional data fields required for rendering. |
| 1440 | """ |
| 1441 | with self._lock: |
| 1442 | task = self._tasks[task_id] |
| 1443 | completed_start = task.completed |
| 1444 | |
| 1445 | if total is not None and total != task.total: |
| 1446 | task.total = total |
| 1447 | task._reset() |
| 1448 | if advance is not None: |
| 1449 | task.completed += advance |
| 1450 | if completed is not None: |
| 1451 | task.completed = completed |
| 1452 | if description is not None: |
| 1453 | task.description = description |
| 1454 | if visible is not None: |
| 1455 | task.visible = visible |
| 1456 | task.fields.update(fields) |
| 1457 | update_completed = task.completed - completed_start |
| 1458 | |
| 1459 | current_time = self.get_time() |
| 1460 | old_sample_time = current_time - self.speed_estimate_period |
| 1461 | _progress = task._progress |
| 1462 | |
| 1463 | popleft = _progress.popleft |
| 1464 | while _progress and _progress[0].timestamp < old_sample_time: |
| 1465 | popleft() |
| 1466 | if update_completed > 0: |
| 1467 | _progress.append(ProgressSample(current_time, update_completed)) |
| 1468 | if ( |
| 1469 | task.total is not None |
| 1470 | and task.completed >= task.total |
| 1471 | and task.finished_time is None |
| 1472 | ): |
| 1473 | task.finished_time = task.elapsed |
| 1474 |