mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-07 12:30:06 +00:00
Merge pull request #486 from sasjs/fix-poll-logic
fix(poll): add default poll options
This commit is contained in:
@@ -21,11 +21,14 @@ export async function pollJobState(
|
|||||||
let pollInterval = 300
|
let pollInterval = 300
|
||||||
let maxPollCount = 1000
|
let maxPollCount = 1000
|
||||||
|
|
||||||
if (pollOptions) {
|
const defaultPollOptions: PollOptions = {
|
||||||
pollInterval = pollOptions.pollInterval || pollInterval
|
maxPollCount,
|
||||||
maxPollCount = pollOptions.maxPollCount || maxPollCount
|
pollInterval,
|
||||||
|
streamLog: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pollOptions = { ...defaultPollOptions, ...(pollOptions || {}) }
|
||||||
|
|
||||||
const stateLink = postedJob.links.find((l: any) => l.rel === 'state')
|
const stateLink = postedJob.links.find((l: any) => l.rel === 'state')
|
||||||
if (!stateLink) {
|
if (!stateLink) {
|
||||||
throw new Error(`Job state link was not found.`)
|
throw new Error(`Job state link was not found.`)
|
||||||
@@ -52,7 +55,7 @@ export async function pollJobState(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let logFileStream
|
let logFileStream
|
||||||
if (pollOptions?.streamLog) {
|
if (pollOptions.streamLog) {
|
||||||
const logPath = pollOptions?.logFolderPath || process.cwd()
|
const logPath = pollOptions?.logFolderPath || process.cwd()
|
||||||
const isFolderPath = await isFolder(logPath)
|
const isFolderPath = await isFolder(logPath)
|
||||||
if (isFolderPath) {
|
if (isFolderPath) {
|
||||||
@@ -69,6 +72,7 @@ export async function pollJobState(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Poll up to the first 100 times with the specified poll interval
|
||||||
let result = await doPoll(
|
let result = await doPoll(
|
||||||
requestClient,
|
requestClient,
|
||||||
postedJob,
|
postedJob,
|
||||||
@@ -76,14 +80,18 @@ export async function pollJobState(
|
|||||||
debug,
|
debug,
|
||||||
pollCount,
|
pollCount,
|
||||||
authConfig,
|
authConfig,
|
||||||
pollOptions,
|
{
|
||||||
|
...pollOptions,
|
||||||
|
maxPollCount:
|
||||||
|
pollOptions.maxPollCount <= 100 ? pollOptions.maxPollCount : 100
|
||||||
|
},
|
||||||
logFileStream
|
logFileStream
|
||||||
)
|
)
|
||||||
|
|
||||||
currentState = result.state
|
currentState = result.state
|
||||||
pollCount = result.pollCount
|
pollCount = result.pollCount
|
||||||
|
|
||||||
if (!needsRetry(currentState) || pollCount >= maxPollCount) {
|
if (!needsRetry(currentState) || pollCount >= pollOptions.maxPollCount) {
|
||||||
return currentState
|
return currentState
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,7 +200,7 @@ const doPoll = async (
|
|||||||
throw new Error(`Job state link was not found.`)
|
throw new Error(`Job state link was not found.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
while (needsRetry(state) && pollCount <= 100 && pollCount <= maxPollCount) {
|
while (needsRetry(state) && pollCount <= maxPollCount) {
|
||||||
state = await getJobState(
|
state = await getJobState(
|
||||||
requestClient,
|
requestClient,
|
||||||
postedJob,
|
postedJob,
|
||||||
|
|||||||
Reference in New Issue
Block a user