Skip to content

Commit 5ce1df6

Browse files
authored
Add instance timeout (#253)
- add instance level timeout, `New-ServiceNowSession -TimeoutSec`
1 parent 5dbf605 commit 5ce1df6

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

ServiceNow/Private/Invoke-ServiceNowRestMethod.ps1

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,6 @@ function Invoke-ServiceNowRestMethod {
138138
$params.Body = [System.Text.Encoding]::UTf8.GetBytes($Body)
139139
}
140140

141-
# if ( $Body ) {
142-
# $params.Body = $Body
143-
# }
144-
145-
# Write-Verbose ($params | ConvertTo-Json)
146-
147141
# hide invoke-webrequest progress
148142
$oldProgressPreference = $ProgressPreference
149143
$ProgressPreference = 'SilentlyContinue'

ServiceNow/Public/New-ServiceNowSession.ps1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ Use GraphQL instead of REST calls
3535
.PARAMETER GetAllTable
3636
Populate $ServiceNowTable with data from all tables the user has access to
3737
38+
.PARAMETER TimeoutSec
39+
Timeout in seconds for all operations.
40+
The default is 0 which represents no timeout.
41+
3842
.PARAMETER PassThru
3943
Provide the resulting session object to the pipeline as opposed to setting as a script scoped variable to be used by default for other calls.
4044
This is useful if you want to have multiple sessions with different api versions, credentials, etc.
@@ -119,6 +123,10 @@ function New-ServiceNowSession {
119123
[Parameter()]
120124
[switch] $GraphQL,
121125

126+
[Parameter()]
127+
[ValidateRange(0, [int32]::MaxValue)]
128+
[int32] $TimeoutSec = 0,
129+
122130
[Parameter()]
123131
[switch] $PassThru
124132
)
@@ -148,6 +156,9 @@ function New-ServiceNowSession {
148156
}
149157
}
150158

159+
$script:PSDefaultParameterValues['Invoke-WebRequest:TimeoutSec'] = $TimeoutSec
160+
$script:PSDefaultParameterValues['Invoke-RestMethodt:TimeoutSec'] = $TimeoutSec
161+
151162
switch -Wildcard ($PSCmdLet.ParameterSetName) {
152163
'OAuth*' {
153164
$params = @{

0 commit comments

Comments
 (0)