Initial commit
This commit is contained in:
commit
6bf433c9a9
20 changed files with 1162 additions and 0 deletions
67
Public/GpfsJob.ps1
Normal file
67
Public/GpfsJob.ps1
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
function Get-GpfsJob {
|
||||
[CmdletBinding(DefaultParameterSetName = 'All')]
|
||||
param(
|
||||
[Parameter(Mandatory, ParameterSetName = 'ById', Position = 0)]
|
||||
[string]$JobId,
|
||||
|
||||
[Parameter(ParameterSetName = 'All')]
|
||||
[ValidateSet('RUNNING', 'COMPLETED', 'FAILED', 'CANCELLED')]
|
||||
[string]$Status
|
||||
)
|
||||
|
||||
if ($PSCmdlet.ParameterSetName -eq 'ById') {
|
||||
Invoke-GpfsApiRequest -Method GET -Endpoint "jobs/$JobId"
|
||||
}
|
||||
else {
|
||||
$params = @{ Method = 'GET'; Endpoint = 'jobs' }
|
||||
if ($Status) {
|
||||
$params['QueryParameters'] = @{ status = $Status }
|
||||
}
|
||||
Invoke-GpfsApiRequest @params
|
||||
}
|
||||
}
|
||||
|
||||
function Remove-GpfsJob {
|
||||
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
|
||||
param(
|
||||
[Parameter(Mandatory, Position = 0)]
|
||||
[string]$JobId
|
||||
)
|
||||
|
||||
if ($PSCmdlet.ShouldProcess($JobId, 'Remove job')) {
|
||||
Invoke-GpfsApiRequest -Method DELETE -Endpoint "jobs/$JobId"
|
||||
}
|
||||
}
|
||||
|
||||
function Wait-GpfsJob {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory, Position = 0)]
|
||||
[string]$JobId,
|
||||
|
||||
[Parameter()]
|
||||
[int]$PollingIntervalSeconds = 5,
|
||||
|
||||
[Parameter()]
|
||||
[int]$TimeoutSeconds = 300
|
||||
)
|
||||
|
||||
$start = Get-Date
|
||||
|
||||
do {
|
||||
Start-Sleep -Seconds $PollingIntervalSeconds
|
||||
|
||||
$job = Invoke-GpfsApiRequest -Method GET -Endpoint "jobs/$JobId"
|
||||
$currentStatus = $job.jobs[0].status
|
||||
|
||||
Write-Verbose "Job $JobId status: $currentStatus"
|
||||
|
||||
if ($currentStatus -in @('COMPLETED', 'FAILED', 'CANCELLED')) {
|
||||
return $job
|
||||
}
|
||||
|
||||
if (((Get-Date) - $start).TotalSeconds -ge $TimeoutSeconds) {
|
||||
throw "Timed out waiting for job $JobId after $TimeoutSeconds seconds."
|
||||
}
|
||||
} while ($true)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue