Skip to content

🚀[Feature]: Add support to specify Delay as a timespan string #2

Description

Description

Desired interface:

Retry {
   Get-Process
} -Delay 2m -Count 5

Function could be called Invoke-RetryableBlock, take [int] $Retries, [?]$WaitTime (should take a RFC8601 timespan where you can define retries as 15s, 3m, 5h or a combination.

Needs a function to convert a stimespan string (RFC8601) to a timespan:

function Convert-TimeStringToTimeSpan {
    param (
        [string]$TimeString
    )

    # Initialize variables to store time components
    $seconds = 0
    $minutes = 0
    $hours = 0
    $days = 0

    # Regular expressions to find time components
    if ($TimeString -match '(\d+)s') {
        $seconds = [int]$matches[1]
    }
    if ($TimeString -match '(\d+)m') {
        $minutes = [int]$matches[1]
    }
    if ($TimeString -match '(\d+)h') {
        $hours = [int]$matches[1]
    }
    if ($TimeString -match '(\d+)d') {
        $days = [int]$matches[1]
    }

    # Create a TimeSpan object
    $timeSpan = New-TimeSpan -Days $days -Hours $hours -Minutes $minutes -Seconds $seconds
    return $timeSpan
}

Convert-TimeStringToTimeSpan -TimeString 15s1m5h
Convert-TimeStringToTimeSpan -TimeString 15s

Tip: https://blog.danskingdom.com/A-PowerShell-function-to-easily-retry-any-code/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions