-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathFlushRequestQueue.ps1
83 lines (78 loc) · 2.23 KB
/
FlushRequestQueue.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<#
.Synopsis
Flushes the Request Queue
.Description
Flushes the Queue of pending Invoke-ADORestApi calls.
#>
param(
# The name of the invoker command
[Parameter(Mandatory)]
[ValidateSet('Invoke-ADORestAPI','Invoke-GitHubRESTApi')]
[string]
$Invoker
)
if ((-not $t) -or (-not $progId)) {
$c, $t, $progId = 0, $rq.Count, $(Get-Random)
}
while ($rq.Count) {
$invokeSplat = $rq.Dequeue()
if ($invokeParams) {
$invokeSplat += $invokeParams
}
$invokeSplatUrl = $invokeSplat.Url, $invokeSplat.uri -ne $null
if ("$invokeSplatUrl".StartsWith('/')) {
$invokeSplatUrl =
@(
"$server".TrimEnd('/') # * The Server
"/$organization"
$invokeSplatUrl
) -join ''
$invokeSplat.Remove('Url')
$invokeSplat.Remove('Uri')
$invokeSplat.Url = $invokeSplatUrl
}
if ($ApiVersion -and -not $invokeSplat.QueryParameter.apiVersion) {
if (-not $invokeSplat.QueryParameter) {
$invokeSplat.QueryParameter = @{}
}
$invokeSplat.QueryParameter.'api-version' = $ApiVersion
}
$status =
if ($invokeSplat.Status) {
$invokeSplat.Status
$invokeSplat.Remove('Status')
}
elseif ($invokeSplat.Method) {
$invokeSplat.Method
} else
{
"GET"
}
$activity =
if ($invokeSplat.Activity) {
$invokeSplat.Activity
$invokeSplat.Remove('Activity')
}
elseif ($invokeSplatUrl) {
$invokeSplatUrl
} else
{
" "
}
if (-not $InvokeSplat.Property) {
$InvokeSplat.Property = [Ordered]@{}
}
if ($organization -and -not $InvokeSplat.Property.Organization) {
$InvokeSplat.Property.Organization = $organization
}
if ($ProjectID -and -not $InvokeSplat.Property.Organization) {
$InvokeSplat.Property.ProjectID = $ProjectID
}
$c++
$p = $c* 100/$t
Write-Progress $status $activity -PercentComplete $p -Id $progId
& $ExecutionContext.SessionState.InvokeCommand.GetCommand($Invoker, 'Function') @invokeSplat
}
if ($c -eq $t) {
Write-Progress $status $activity -Completed $progId
}