Add elapsed return value to select modules (#37969)

* Add elapsed return value to select modules

It can be quite useful to know exactly how much time has elapsed
downloading/waiting. This improves existing modules or updates
documentation.

* Ensure elapsed is always returned

* Added changelog fragment
This commit is contained in:
Dag Wieers 2018-08-31 22:20:56 +02:00 committed by GitHub
commit b64e666643
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 141 additions and 90 deletions

View file

@ -23,6 +23,7 @@ $timeout = Get-AnsibleParam -obj $params -name "timeout" -type "int" -default 30
$result = @{
changed = $false
elapsed = 0
}
# validate the input with the various options
@ -126,9 +127,8 @@ if ($path -eq $null -and $port -eq $null -and $state -ne "drained") {
}
if ($complete -eq $false) {
$elapsed_seconds = ((Get-Date) - $module_start).TotalSeconds
$result.elapsed = ((Get-Date) - $module_start).TotalSeconds
$result.wait_attempts = $attempts
$result.elapsed = $elapsed_seconds
if ($search_regex -eq $null) {
Fail-Json $result "timeout while waiting for file $path to be present"
} else {
@ -158,9 +158,8 @@ if ($path -eq $null -and $port -eq $null -and $state -ne "drained") {
}
if ($complete -eq $false) {
$elapsed_seconds = ((Get-Date) - $module_start).TotalSeconds
$result.elapsed = ((Get-Date) - $module_start).TotalSeconds
$result.wait_attempts = $attempts
$result.elapsed = $elapsed_seconds
if ($search_regex -eq $null) {
Fail-Json $result "timeout while waiting for file $path to be absent"
} else {
@ -185,9 +184,8 @@ if ($path -eq $null -and $port -eq $null -and $state -ne "drained") {
}
if ($complete -eq $false) {
$elapsed_seconds = ((Get-Date) - $module_start).TotalSeconds
$result.elapsed = ((Get-Date) - $module_start).TotalSeconds
$result.wait_attempts = $attempts
$result.elapsed = $elapsed_seconds
Fail-Json $result "timeout while waiting for $($hostname):$port to start listening"
}
} elseif ($state -in @("stopped","absent")) {
@ -206,9 +204,8 @@ if ($path -eq $null -and $port -eq $null -and $state -ne "drained") {
}
if ($complete -eq $false) {
$elapsed_seconds = ((Get-Date) - $module_start).TotalSeconds
$result.elapsed = ((Get-Date) - $module_start).TotalSeconds
$result.wait_attempts = $attempts
$result.elapsed = $elapsed_seconds
Fail-Json $result "timeout while waiting for $($hostname):$port to stop listening"
}
} elseif ($state -eq "drained") {
@ -247,15 +244,14 @@ if ($path -eq $null -and $port -eq $null -and $state -ne "drained") {
}
if ($complete -eq $false) {
$elapsed_seconds = ((Get-Date) - $module_start).TotalSeconds
$result.elapsed = ((Get-Date) - $module_start).TotalSeconds
$result.wait_attempts = $attempts
$result.elapsed = $elapsed_seconds
Fail-Json $result "timeout while waiting for $($hostname):$port to drain"
}
}
}
$result.wait_attempts = $attempts
$result.elapsed = ((Get-Date) - $module_start).TotalSeconds
$result.wait_attempts = $attempts
Exit-Json $result