Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
Commit9b6dba1
committed
feature#46242 [Console] Add support for resuming a ProgressBar (yivi)
This PR was squashed before being merged into the 6.2 branch.Discussion----------[Console] Add support for resuming a ProgressBarAdd an `(int) $resumeAt` argument for `ProgressBar#start()`, so that the progress bar is initialized at a specific progress level, with a new property so that `getEstimated()` and `getRemaining()` report the right number.| Q | A| ------------- | ---| Branch? | 6.1| Bug fix? | no| New feature? | yes| Deprecations? | no| License | MITAs pointed out on a recently posted [SO question](https://stackoverflow.com/q/72097256/1426539)), when working on a longish task one may want to create a progress bar for a _resumed_ task.Calling `advance()` works to increase the progress bar counter, but the results of `getRemaining()` and `getEstimated()` will be "broken", since whatever steps one "skipped" will be considered to have taken 0 seconds. For a longer running task, the estimation will be **very** inaccurate, and will remain so for a long while. Using the example code from the linked question:```php$itemCount = 1_000_000;$startItem = 150_000;$progressBar = new ProgressBar($output, $itemCount);$progressBar->setFormat( $progressBar->getFormatDefinition(ProgressBar::FORMAT_DEBUG));$progressBar->start();if ($startItem !== 0) { // unfortunately taken into account in ETA calculation $progressBar->advance($startItem);}for ($i = $startItem; $i < $itemCount; $i++) { usleep(50_000); $progressBar->advance();}```This will output this to begin with:```none150038/1000000 [====>-----------------------] 15% 2 secs/13 secs 20.0 MiB```The estimated time will keep growing as the tasks progresses, but the estimation won't be remotely useful for a long while.This PR adds a `$resumeAt` parameter to `ProgresBar#start()`, so that's possible to write:```php$bar = new ProgressBar($output, 1_200_000, 0);$bar->start(null, 300_000);```And calls to `$bar->getEstimated()` and `$bar->getRemaining()` will return sane results (and calling the initial `->advance()` would be no longer necessary).### TODO:- [ ] submit changes to the documentation (if the PR is well received)Commits-------8e1596e [Console] Add support for resuming a ProgressBarFile tree
3 files changed
+76
-7
lines changed- src/Symfony/Component/Console
- Helper
- Tests/Helper
3 files changed
+76
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
199 | 200 | | |
200 | 201 | | |
201 | 202 | | |
202 | | - | |
| 203 | + | |
203 | 204 | | |
204 | 205 | | |
205 | 206 | | |
206 | | - | |
| 207 | + | |
207 | 208 | | |
208 | 209 | | |
209 | 210 | | |
| |||
212 | 213 | | |
213 | 214 | | |
214 | 215 | | |
215 | | - | |
| 216 | + | |
216 | 217 | | |
217 | 218 | | |
218 | 219 | | |
| |||
302 | 303 | | |
303 | 304 | | |
304 | 305 | | |
305 | | - | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
306 | 309 | | |
307 | | - | |
| 310 | + | |
308 | 311 | | |
309 | 312 | | |
310 | | - | |
311 | | - | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
312 | 317 | | |
313 | 318 | | |
314 | 319 | | |
| |||
Lines changed: 63 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
69 | 132 | | |
70 | 133 | | |
71 | 134 | | |
| |||
0 commit comments
Comments
(0)