Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Parameter: Start-Sleep [-Duration] <timespan> #16185

Merged

Conversation

IISResetMe
Copy link
Collaborator

@IISResetMe IISResetMe commented Oct 1, 2021

PR Context

As originally propoesd in #12305, this PR adds a new -Duration parameter to the Start-Sleep cmdlet:

$duration = New-TimeSpan -Seconds 2

# -Duration accepts a [timespan] value
Start-Sleep -Duration $duration

# Supports positional binding
Start-Sleep $duration

# As well as pipeline binding
$duration |Start-Sleep

The existing parameter sets of Start-Sleep remain the same, and I have not changed the DefaultParameterSetName, but the pipeline binding does interferes with the existing (buggy/counter-intuitive) binding behavior:

$ts = New-TimeSpan -Seconds 62 
$ts |Start-Sleep 

This PR also adds range validation support for [timespan] values via [ValidateRange()]:

function Test-TimeMachine {
  param(
    # The time machine can only go back in time
    [ValidateRange('NonPositive')]
    [timespan]$Distance
  )
  
  # time-travel $Distance and back again
}

Strict range validation is not of much immediate use, but in a possible future with timespan literals we could do:

function Request-Vacation {
  param(
    [ValidateRange(1d, 60d)]
    [timespan]$Duration
  )
  
  # ...
}

PR Context

I believe this change is reasonable to make without wrapping in an Experimental Feature - the behavior that we're breaking ("piped [timespan] values are interpreted as seconds % 60") is rather counter-intuitive and deceptive.

PR Checklist

@ghost ghost assigned daxian-dbw Oct 1, 2021
@iSazonov
Copy link
Collaborator

iSazonov commented Oct 2, 2021

My understanding of PowerShell Committee conclusion in #12305 (comment) is that we need to implement something like

Start-Sleep 3sec
Start-Sleep 1.5min

The PR is not follow the conclusion.

@IISResetMe
Copy link
Collaborator Author

IISResetMe commented Oct 2, 2021

@iSazonov In order for that to ever work consistently, this change is needed. Without an option for binding [timespan] values the following would produce unexpected results:

# this would return after only 5 seconds
1m5sec |Start-Sleep

# ... for the same reason that this _currently_ returns after only 5 seconds
New-TimeSpan -Minutes 1 -Seconds 5 |Start-Sleep

@ghost ghost added the Review - Needed The PR is being reviewed label Oct 10, 2021
@ghost
Copy link

ghost commented Oct 10, 2021

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@ghost ghost added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Review - Needed The PR is being reviewed Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept labels Oct 28, 2021
@daxian-dbw daxian-dbw added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log labels Nov 2, 2021
…rtSleepCommand.cs

Co-authored-by: Dongbo Wang <dongbow@microsoft.com>
@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Nov 28, 2021
@ghost ghost added the Review - Needed The PR is being reviewed label Dec 6, 2021
@ghost
Copy link

ghost commented Dec 6, 2021

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@daxian-dbw daxian-dbw added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Review - Needed The PR is being reviewed labels Dec 6, 2021
@ghost ghost added the Stale label Dec 21, 2021
@ghost
Copy link

ghost commented Dec 21, 2021

This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 15 days. It will be closed if no further activity occurs within 10 days of this comment.

@ghost ghost removed the Stale label Dec 22, 2021
@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Dec 31, 2021
@ghost ghost added the Review - Needed The PR is being reviewed label Jan 7, 2022
@ghost
Copy link

ghost commented Jan 7, 2022

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@daxian-dbw daxian-dbw added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Review - Needed The PR is being reviewed labels Jan 7, 2022
@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Jan 13, 2022
@ghost ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Jan 13, 2022
@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Jan 13, 2022
Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IISResetMe Can you please address the CodeFactor issues? No need to address all, but just those issue related to your new changes.

@pull-request-quantifier-deprecated

This PR has 185 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Medium
Size       : +185 -0
Percentile : 57%

Total files changed: 4

Change summary by file extension:
.cs : +58 -0
.resx : +112 -0
.ps1 : +15 -0

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detetcted.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@IISResetMe
Copy link
Collaborator Author

IISResetMe commented Jan 14, 2022

@IISResetMe Can you please address the CodeFactor issues? No need to address all, but just those issue related to your new changes.

Thanks @daxian-dbw, I believe you already fixed all the relevant ones 😅 - the remaining issues all complain about documentation and I ignored those on purpose since it would break with the description convention in the existing comment docs (the property summaries all start with "Allows sleep time to be ...").

I'm not sure why it says "1 issue", when I click through there's 5 and they all appear to be non-critical

@daxian-dbw daxian-dbw merged commit 686c84c into PowerShell:master Jan 14, 2022
@daxian-dbw
Copy link
Member

daxian-dbw commented Jan 14, 2022

I guess the other 4 are known to CodeRefactor and the remaining one is new :)
If I understand correctly, this PR doesn't mean to close #12305, but just one building step toward the ask in that issue, right?

@IISResetMe
Copy link
Collaborator Author

I guess the other 4 are known to CodeRefactor and the remaining one is new :)

That must be the one for the property I added then, all good!

[...] If I understand correctly, this PR doesn't mean to close #12305, but just one building step toward the ask in that issue, right?

That's exactly right!

The other half of the puzzle in #12305 is implementing tokenization and parsing logic for timespan literals so we can do:

5sec374ms |Start-Sleep

I intend to pick this up too :)

@ghost
Copy link

ghost commented Feb 24, 2022

🎉v7.3.0-preview.2 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Documentation Needed in this repo Documentation is needed in this repo Medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants