sqone2 / PSFive9Admin

Powershell functions for working with the Five9 Admin Web Service API
MIT License
27 stars 13 forks source link

Auto report watch/fetch function suggestion #3

Closed GetterDragon closed 4 years ago

GetterDragon commented 4 years ago

I use this in my own Five9 PowerShell modules and find it helpful for watching a running report by ID and then fetching the results without me needing to consistently check in on it. Providing here if you'd like to add it into your module. Assign it as a variable and pass it the Five9ID and it'll do the rest. Optionally, you can specify the wait time to recheck the report or it will default to 5s retry intervals.. Sorry for the updates, I've not posted comments much to GitHub before so I couldn't get the CODE snippet identifier right.

# Watch report status (While/Until Running=False)
function Get-Five9ReportResults {
    param(
        # Five9 Report Id
        [string]$Five9ReportID,
        # Seconds to retry report status, defaults to 5 if not specified
        [int]$WaitSeconds = 5
    )
    $ReportIsRunning = $true
    While ($ReportIsRunning -eq $true) {
        If($Five9AdminWS.isReportRunning($Five9ReportID,"") -eq $false ) {break :ReportDone}
        Write-Host 'Report is still running...'
        Start-Sleep -Seconds $WaitSeconds
    }
    :ReportDone do {
        Write-Host 'Report finished, retrieving results'

        # Get results and convert from CSV
        $Five9AdminWS.getReportResultCsv($Five9ReportID) | ConvertFrom-Csv

        # Report done, break loop
        $ReportIsRunning = $false
    }
    Until ($ReportIsRunning -eq $false)
}
sqone2 commented 4 years ago

Thanks for the suggestion @GetterDragon! I just updated Get-Five9AgentState to wait for the results as you suggested.

Please let me know if you think of any others!