mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 22:00:22 -07:00
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:
parent
af3bac1320
commit
b64e666643
11 changed files with 141 additions and 90 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue