Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Console] Add support for resuming a ProgressBar#46242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:6.2fromyivi:resumable_progress_bar
Jul 23, 2022
Merged

[Console] Add support for resuming a ProgressBar#46242

fabpot merged 1 commit intosymfony:6.2fromyivi:resumable_progress_bar
Jul 23, 2022

Conversation

@yivi
Copy link
Contributor

@yiviyivi commentedMay 3, 2022
edited
Loading

Add an(int) $resumeAt argument forProgressBar#start(), so that the progress bar is initialized at a specific progress level, with a new property so thatgetEstimated() andgetRemaining() report the right number.

QA
Branch?6.1
Bug fix?no
New feature?yes
Deprecations?no
LicenseMIT

As pointed out on a recently postedSO question), when working on a longish task one may want to create a progress bar for aresumed task.

Callingadvance() works to increase the progress bar counter, but the results ofgetRemaining() andgetEstimated() will be "broken", since whatever steps one "skipped" will be considered to have taken 0 seconds. For a longer running task, the estimation will bevery inaccurate, and will remain so for a long while. Using the example code from the linked question:

$itemCount =1_000_000;$startItem =150_000;$progressBar =newProgressBar($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:

150038/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 toProgresBar#start(), so that's possible to write:

$bar =newProgressBar($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)

GromNaN, chalasr, and BenMorel reacted with thumbs up emojiBossman1337 and BenMorel reacted with rocket emoji
@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has acontribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (seehttps://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (seehttps://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.1 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot
Copy link

Hey!

I think@boesing has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

boesing reacted with thumbs down emoji

@chalasrchalasr modified the milestones:6.1,6.2May 4, 2022
@fabpot
Copy link
Member

Thank you@yivi.

@fabpotfabpot merged commit9b6dba1 intosymfony:6.2Jul 23, 2022
fabpot added a commit that referenced this pull requestAug 5, 2022
…uiluz)This PR was squashed before being merged into the 6.2 branch.Discussion----------[Console] Rename some arguments in ProgressBar| Q             | A| ------------- | ---| Branch?       | 6.2| Bug fix?      | no| New feature?  | no| Deprecations? | no| Tickets       | -| License       | MIT| Doc PR        | -While documenting#46242, I thought something was odd: the code and docs talk about "resuming progress bars". But that's only a use-case of this feature. There are others: e.g. some task with optional steps; if you skip some step, you might want to show the progress at a certain starting point instead of `0`.So, this PR propose to rename some arguments. In any case, this is minor, so feel free to close if you think this is not relevant enough.Commits-------c03e815 [Console] Rename some arguments in ProgressBar
@fabpotfabpot mentioned this pull requestOct 24, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@chalasrchalasrAwaiting requested review from chalasrchalasr is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

6.2

Development

Successfully merging this pull request may close these issues.

4 participants

@yivi@carsonbot@fabpot@chalasr

[8]ページ先頭

©2009-2025 Movatter.jp