1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-19 01:50:06 +00:00

chore(poll-job-status): renamed PollOptions to PollStrategy and added docs

This commit is contained in:
Yury Shkoda
2023-05-15 16:32:07 +03:00
parent f9f4aa5aa6
commit 153b285670
8 changed files with 112 additions and 86 deletions

View File

@@ -9,7 +9,7 @@ import {
File, File,
EditContextInput, EditContextInput,
JobDefinition, JobDefinition,
PollOptions PollStrategy
} from './types' } from './types'
import { import {
CertificateError, CertificateError,
@@ -276,7 +276,7 @@ export class SASViyaApiClient {
* @param debug - when set to true, the log will be returned. * @param debug - when set to true, the log will be returned.
* @param expectWebout - when set to true, the automatic _webout fileref will be checked for content, and that content returned. This fileref is used when the Job contains a SASjs web request (as opposed to executing arbitrary SAS code). * @param expectWebout - when set to true, the automatic _webout fileref will be checked for content, and that content returned. This fileref is used when the Job contains a SASjs web request (as opposed to executing arbitrary SAS code).
* @param waitForResult - when set to true, function will return the session * @param waitForResult - when set to true, function will return the session
* @param pollOptions - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: { MAX_POLL_COUNT: 24 * 60 * 60, POLL_INTERVAL: 1000 }. * @param pollStrategy - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: { maxPollCount: 24 * 60 * 60, pollInterval: 1000 }.
* @param printPid - a boolean that indicates whether the function should print (PID) of the started job. * @param printPid - a boolean that indicates whether the function should print (PID) of the started job.
* @param variables - an object that represents macro variables. * @param variables - an object that represents macro variables.
*/ */
@@ -289,7 +289,7 @@ export class SASViyaApiClient {
debug: boolean = false, debug: boolean = false,
expectWebout = false, expectWebout = false,
waitForResult = true, waitForResult = true,
pollOptions?: PollOptions, pollStrategy?: PollStrategy,
printPid = false, printPid = false,
variables?: MacroVar variables?: MacroVar
): Promise<any> { ): Promise<any> {
@@ -305,7 +305,7 @@ export class SASViyaApiClient {
debug, debug,
expectWebout, expectWebout,
waitForResult, waitForResult,
pollOptions, pollStrategy,
printPid, printPid,
variables variables
) )
@@ -627,7 +627,7 @@ export class SASViyaApiClient {
* @param accessToken - an optional access token for an authorized user. * @param accessToken - an optional access token for an authorized user.
* @param waitForResult - a boolean indicating if the function should wait for a result. * @param waitForResult - a boolean indicating if the function should wait for a result.
* @param expectWebout - a boolean indicating whether to expect a _webout response. * @param expectWebout - a boolean indicating whether to expect a _webout response.
* @param pollOptions - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: { MAX_POLL_COUNT: 24 * 60 * 60, POLL_INTERVAL: 1000 }. * @param pollStrategy - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: { maxPollCount: 24 * 60 * 60, pollInterval: 1000 }.
* @param printPid - a boolean that indicates whether the function should print (PID) of the started job. * @param printPid - a boolean that indicates whether the function should print (PID) of the started job.
* @param variables - an object that represents macro variables. * @param variables - an object that represents macro variables.
*/ */
@@ -639,7 +639,7 @@ export class SASViyaApiClient {
authConfig?: AuthConfig, authConfig?: AuthConfig,
waitForResult = true, waitForResult = true,
expectWebout = false, expectWebout = false,
pollOptions?: PollOptions, pollStrategy?: PollStrategy,
printPid = false, printPid = false,
variables?: MacroVar variables?: MacroVar
) { ) {
@@ -718,7 +718,7 @@ export class SASViyaApiClient {
debug, debug,
expectWebout, expectWebout,
waitForResult, waitForResult,
pollOptions, pollStrategy,
printPid, printPid,
variables variables
) )
@@ -910,14 +910,14 @@ export class SASViyaApiClient {
private async pollJobState( private async pollJobState(
postedJob: Job, postedJob: Job,
authConfig?: AuthConfig, authConfig?: AuthConfig,
pollOptions?: PollOptions pollStrategy?: PollStrategy
) { ) {
return pollJobState( return pollJobState(
this.requestClient, this.requestClient,
postedJob, postedJob,
this.debug, this.debug,
authConfig, authConfig,
pollOptions pollStrategy
) )
} }

View File

@@ -3,7 +3,7 @@ import {
SASjsConfig, SASjsConfig,
UploadFile, UploadFile,
EditContextInput, EditContextInput,
PollOptions, PollStrategy,
LoginMechanism LoginMechanism
} from './types' } from './types'
import { SASViyaApiClient } from './SASViyaApiClient' import { SASViyaApiClient } from './SASViyaApiClient'
@@ -851,7 +851,7 @@ export default class SASjs {
* @param authConfig - a valid client, secret, refresh and access tokens that are authorised to execute compute jobs. * @param authConfig - a valid client, secret, refresh and access tokens that are authorised to execute compute jobs.
* The access token is not required when the user is authenticated via the browser. * The access token is not required when the user is authenticated via the browser.
* @param waitForResult - a boolean that indicates whether the function needs to wait for execution to complete. * @param waitForResult - a boolean that indicates whether the function needs to wait for execution to complete.
* @param pollOptions - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: { MAX_POLL_COUNT: 24 * 60 * 60, POLL_INTERVAL: 1000 }. * @param pollStrategy - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: { maxPollCount: 24 * 60 * 60, pollInterval: 1000 }.
* @param printPid - a boolean that indicates whether the function should print (PID) of the started job. * @param printPid - a boolean that indicates whether the function should print (PID) of the started job.
* @param variables - an object that represents macro variables. * @param variables - an object that represents macro variables.
*/ */
@@ -861,7 +861,7 @@ export default class SASjs {
config: any = {}, config: any = {},
authConfig?: AuthConfig, authConfig?: AuthConfig,
waitForResult?: boolean, waitForResult?: boolean,
pollOptions?: PollOptions, pollStrategy?: PollStrategy,
printPid = false, printPid = false,
variables?: MacroVar variables?: MacroVar
) { ) {
@@ -885,7 +885,7 @@ export default class SASjs {
authConfig, authConfig,
!!waitForResult, !!waitForResult,
false, false,
pollOptions, pollStrategy,
printPid, printPid,
variables variables
) )

View File

@@ -2,7 +2,7 @@ import { timestampToYYYYMMDDHHMMSS } from '@sasjs/utils/time'
import { AuthConfig, MacroVar } from '@sasjs/utils/types' import { AuthConfig, MacroVar } from '@sasjs/utils/types'
import { prefixMessage } from '@sasjs/utils/error' import { prefixMessage } from '@sasjs/utils/error'
import { import {
PollOptions, PollStrategy,
Job, Job,
ComputeJobExecutionError, ComputeJobExecutionError,
NotFoundError NotFoundError
@@ -25,7 +25,7 @@ import { uploadTables } from './uploadTables'
* @param debug - when set to true, the log will be returned. * @param debug - when set to true, the log will be returned.
* @param expectWebout - when set to true, the automatic _webout fileref will be checked for content, and that content returned. This fileref is used when the Job contains a SASjs web request (as opposed to executing arbitrary SAS code). * @param expectWebout - when set to true, the automatic _webout fileref will be checked for content, and that content returned. This fileref is used when the Job contains a SASjs web request (as opposed to executing arbitrary SAS code).
* @param waitForResult - when set to true, function will return the session * @param waitForResult - when set to true, function will return the session
* @param pollOptions - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: { MAX_POLL_COUNT: 24 * 60 * 60, POLL_INTERVAL: 1000 }. * @param pollStrategy - an object that represents poll interval(milliseconds) and maximum amount of attempts. Object example: { maxPollCount: 24 * 60 * 60, pollInterval: 1000 }.
* @param printPid - a boolean that indicates whether the function should print (PID) of the started job. * @param printPid - a boolean that indicates whether the function should print (PID) of the started job.
* @param variables - an object that represents macro variables. * @param variables - an object that represents macro variables.
*/ */
@@ -41,7 +41,7 @@ export async function executeScript(
debug: boolean = false, debug: boolean = false,
expectWebout = false, expectWebout = false,
waitForResult = true, waitForResult = true,
pollOptions?: PollOptions, pollStrategy?: PollStrategy,
printPid = false, printPid = false,
variables?: MacroVar variables?: MacroVar
): Promise<any> { ): Promise<any> {
@@ -179,7 +179,7 @@ export async function executeScript(
postedJob, postedJob,
debug, debug,
authConfig, authConfig,
pollOptions pollStrategy
).catch(async (err) => { ).catch(async (err) => {
const error = err?.response?.data const error = err?.response?.data
const result = /err=[0-9]*,/.exec(error) const result = /err=[0-9]*,/.exec(error)

View File

@@ -1,5 +1,5 @@
import { AuthConfig } from '@sasjs/utils/types' import { AuthConfig } from '@sasjs/utils/types'
import { Job, PollOptions } from '../..' import { Job, PollStrategy, PollStrategies } from '../..'
import { getTokens } from '../../auth/getTokens' import { getTokens } from '../../auth/getTokens'
import { RequestClient } from '../../request/RequestClient' import { RequestClient } from '../../request/RequestClient'
import { JobStatePollError } from '../../types/errors' import { JobStatePollError } from '../../types/errors'
@@ -16,31 +16,55 @@ export enum JobState {
Error = 'error' Error = 'error'
} }
type PollStrategies = PollOptions[] /**
* Polls job status using default or provided poll strategies.
* @param requestClient - the pre-configured HTTP request client.
* @param postedJob - the relative or absolute path to the job.
* @param debug - sets the _debug flag in the job arguments.
* @param authConfig - an access token, refresh token, client and secret for an authorized user.
* @param pollStrategy - an object containing maxPollCount, pollInterval, streamLog and logFolderPath. It will override the first default poll strategy if provided.
* Example:
* { maxPollCount: 200, pollInterval: 300, streamLog: false }
* @param pollStrategies - an array of poll strategies. It will override default poll strategies if provided.
* Example:
* [
* { maxPollCount: 200, pollInterval: 300, streamLog: false },
* { maxPollCount: 300, pollInterval: 3000, streamLog: false },
* { maxPollCount: 500, pollInterval: 30000, streamLog: false }
* ]
* Default poll strategies:
* [
* { maxPollCount: 200, pollInterval: 300, streamLog: false }, // INFO: approximately ~2 mins (including time to get response (~300ms))
* { maxPollCount: 300, pollInterval: 3000, streamLog: false }, // INFO: approximately ~5.5 mins (including time to get response (~300ms))
* { maxPollCount: 400, pollInterval: 30000, streamLog: false }, // INFO: approximately ~50.5 mins (including time to get response (~300ms))
* { maxPollCount: 3400, pollInterval: 60000, streamLog: false } // INFO: approximately ~3015 mins (~125 hours) (including time to get response (~300ms))
* ]
* @returns - a promise which resolves with a job state
*/
export async function pollJobState( export async function pollJobState(
requestClient: RequestClient, requestClient: RequestClient,
postedJob: Job, postedJob: Job,
debug: boolean, debug: boolean,
authConfig?: AuthConfig, authConfig?: AuthConfig,
pollOptions?: PollOptions, pollStrategy?: PollStrategy,
pollStrategies?: PollStrategies pollStrategies?: PollStrategies
) { ): Promise<JobState> {
const logger = process.logger || console const logger = process.logger || console
const defaultStreamLog = pollStrategy ? pollStrategy.streamLog : false
const defaultPollStrategies: PollStrategies = [ const defaultPollStrategies: PollStrategies = [
{ maxPollCount: 200, pollInterval: 300, streamLog: false }, // INFO: approximately ~2 mins (including time to get response (~300ms)) { maxPollCount: 200, pollInterval: 300, streamLog: defaultStreamLog },
{ maxPollCount: 300, pollInterval: 3000, streamLog: false }, // INFO: approximately ~5.5 mins (including time to get response (~300ms)) { maxPollCount: 300, pollInterval: 3000, streamLog: defaultStreamLog },
{ maxPollCount: 400, pollInterval: 30000, streamLog: false }, // INFO: approximately ~50.5 mins (including time to get response (~300ms)) { maxPollCount: 400, pollInterval: 30000, streamLog: defaultStreamLog },
{ maxPollCount: 3400, pollInterval: 60000, streamLog: false } // INFO: approximately ~3015 mins (~125 hours) (including time to get response (~300ms)) { maxPollCount: 3400, pollInterval: 60000, streamLog: defaultStreamLog }
] ]
if (pollStrategies === undefined) pollStrategies = defaultPollStrategies if (pollStrategies === undefined) pollStrategies = defaultPollStrategies
else validatePollStrategies(pollStrategies) else validatePollStrategies(pollStrategies)
let defaultPollOptions: PollOptions = pollStrategies.splice(0, 1)[0] let defaultPollStrategy: PollStrategy = pollStrategies.splice(0, 1)[0]
pollOptions = { ...defaultPollOptions, ...(pollOptions || {}) } pollStrategy = { ...defaultPollStrategy, ...(pollStrategy || {}) }
const stateLink = postedJob.links.find((l: any) => l.rel === 'state') const stateLink = postedJob.links.find((l: any) => l.rel === 'state')
if (!stateLink) { if (!stateLink) {
@@ -69,9 +93,9 @@ export async function pollJobState(
} }
let logFileStream let logFileStream
if (pollOptions.streamLog && isNode()) { if (pollStrategy.streamLog && isNode()) {
const { getFileStream } = require('./getFileStream') const { getFileStream } = require('./getFileStream')
logFileStream = await getFileStream(postedJob, pollOptions.logFolderPath) logFileStream = await getFileStream(postedJob, pollStrategy.logFolderPath)
} }
let result = await doPoll( let result = await doPoll(
@@ -80,7 +104,7 @@ export async function pollJobState(
currentState, currentState,
debug, debug,
pollCount, pollCount,
pollOptions, pollStrategy,
authConfig, authConfig,
logFileStream logFileStream
) )
@@ -90,7 +114,7 @@ export async function pollJobState(
if ( if (
!needsRetry(currentState) || !needsRetry(currentState) ||
(pollCount >= pollOptions.maxPollCount && !pollStrategies.length) (pollCount >= pollStrategy.maxPollCount && !pollStrategies.length)
) { ) {
return currentState return currentState
} }
@@ -98,11 +122,11 @@ export async function pollJobState(
// INFO: If we get to this point, this is a long-running job that needs longer polling. // INFO: If we get to this point, this is a long-running job that needs longer polling.
// We will resume polling with a bigger interval according to the next polling strategy // We will resume polling with a bigger interval according to the next polling strategy
while (pollStrategies.length && needsRetry(currentState)) { while (pollStrategies.length && needsRetry(currentState)) {
defaultPollOptions = pollStrategies.splice(0, 1)[0] defaultPollStrategy = pollStrategies.splice(0, 1)[0]
if (pollOptions) { if (pollStrategy) {
defaultPollOptions.streamLog = pollOptions.streamLog defaultPollStrategy.streamLog = pollStrategy.streamLog
defaultPollOptions.logFolderPath = pollOptions.logFolderPath defaultPollStrategy.logFolderPath = pollStrategy.logFolderPath
} }
result = await doPoll( result = await doPoll(
@@ -111,7 +135,7 @@ export async function pollJobState(
currentState, currentState,
debug, debug,
pollCount, pollCount,
defaultPollOptions, defaultPollStrategy,
authConfig, authConfig,
logFileStream logFileStream
) )
@@ -169,11 +193,11 @@ const doPoll = async (
currentState: JobState, currentState: JobState,
debug: boolean, debug: boolean,
pollCount: number, pollCount: number,
pollOptions: PollOptions, pollStrategy: PollStrategy,
authConfig?: AuthConfig, authConfig?: AuthConfig,
logStream?: WriteStream logStream?: WriteStream
): Promise<{ state: JobState; pollCount: number }> => { ): Promise<{ state: JobState; pollCount: number }> => {
const { maxPollCount, pollInterval } = pollOptions const { maxPollCount, pollInterval } = pollStrategy
const logger = process.logger || console const logger = process.logger || console
const stateLink = postedJob.links.find((l: Link) => l.rel === 'state')! const stateLink = postedJob.links.find((l: Link) => l.rel === 'state')!
let maxErrorCount = 5 let maxErrorCount = 5
@@ -208,7 +232,7 @@ const doPoll = async (
const jobHref = postedJob.links.find((l: Link) => l.rel === 'self')!.href const jobHref = postedJob.links.find((l: Link) => l.rel === 'self')!.href
if (pollOptions?.streamLog) { if (pollStrategy?.streamLog) {
const { result: job } = await requestClient.get<Job>( const { result: job } = await requestClient.get<Job>(
jobHref, jobHref,
authConfig?.access_token authConfig?.access_token
@@ -251,7 +275,7 @@ const doPoll = async (
} }
const validatePollStrategies = (strategies: PollStrategies) => { const validatePollStrategies = (strategies: PollStrategies) => {
const throwError = (message?: string, strategy?: PollOptions) => { const throwError = (message?: string, strategy?: PollStrategy) => {
throw new Error( throw new Error(
`Poll strategies are not valid.${message ? ` ${message}` : ''}${ `Poll strategies are not valid.${message ? ` ${message}` : ''}${
strategy strategy
@@ -263,7 +287,7 @@ const validatePollStrategies = (strategies: PollStrategies) => {
if (!strategies.length) throwError('No strategies provided.') if (!strategies.length) throwError('No strategies provided.')
strategies.forEach((strategy: PollOptions, i: number) => { strategies.forEach((strategy: PollStrategy, i: number) => {
const { maxPollCount, pollInterval } = strategy const { maxPollCount, pollInterval } = strategy
if (maxPollCount < 1) { if (maxPollCount < 1) {

View File

@@ -7,13 +7,13 @@ import * as uploadTablesModule from '../uploadTables'
import * as getTokensModule from '../../../auth/getTokens' import * as getTokensModule from '../../../auth/getTokens'
import * as formatDataModule from '../../../utils/formatDataForRequest' import * as formatDataModule from '../../../utils/formatDataForRequest'
import * as fetchLogsModule from '../../../utils/fetchLogByChunks' import * as fetchLogsModule from '../../../utils/fetchLogByChunks'
import { PollOptions } from '../../../types' import { PollStrategy } from '../../../types'
import { ComputeJobExecutionError, NotFoundError } from '../../../types/errors' import { ComputeJobExecutionError, NotFoundError } from '../../../types/errors'
import { Logger, LogLevel } from '@sasjs/utils' import { Logger, LogLevel } from '@sasjs/utils'
const sessionManager = new (<jest.Mock<SessionManager>>SessionManager)() const sessionManager = new (<jest.Mock<SessionManager>>SessionManager)()
const requestClient = new (<jest.Mock<RequestClient>>RequestClient)() const requestClient = new (<jest.Mock<RequestClient>>RequestClient)()
const defaultPollOptions: PollOptions = { const defaultPollStrategy: PollStrategy = {
maxPollCount: 100, maxPollCount: 100,
pollInterval: 500, pollInterval: 500,
streamLog: false streamLog: false
@@ -98,7 +98,7 @@ describe('executeScript', () => {
false, false,
false, false,
false, false,
defaultPollOptions, defaultPollStrategy,
true true
) )
@@ -126,7 +126,7 @@ describe('executeScript', () => {
false, false,
false, false,
false, false,
defaultPollOptions, defaultPollStrategy,
true true
).catch((e: any) => e) ).catch((e: any) => e)
@@ -152,7 +152,7 @@ describe('executeScript', () => {
false, false,
false, false,
false, false,
defaultPollOptions, defaultPollStrategy,
true true
) )
@@ -176,7 +176,7 @@ describe('executeScript', () => {
false, false,
false, false,
false, false,
defaultPollOptions, defaultPollStrategy,
true true
) )
@@ -202,7 +202,7 @@ describe('executeScript', () => {
false, false,
false, false,
false, false,
defaultPollOptions, defaultPollStrategy,
true true
) )
@@ -248,7 +248,7 @@ describe('executeScript', () => {
true, true,
false, false,
false, false,
defaultPollOptions, defaultPollStrategy,
true true
) )
@@ -295,7 +295,7 @@ describe('executeScript', () => {
true, true,
false, false,
false, false,
defaultPollOptions, defaultPollStrategy,
true true
).catch((e: any) => e) ).catch((e: any) => e)
@@ -315,7 +315,7 @@ describe('executeScript', () => {
true, true,
false, false,
false, false,
defaultPollOptions, defaultPollStrategy,
true true
) )
@@ -335,7 +335,7 @@ describe('executeScript', () => {
false, false,
false, false,
true, true,
defaultPollOptions, defaultPollStrategy,
true true
) )
@@ -344,7 +344,7 @@ describe('executeScript', () => {
mockJob, mockJob,
false, false,
mockAuthConfig, mockAuthConfig,
defaultPollOptions defaultPollStrategy
) )
}) })
@@ -365,7 +365,7 @@ describe('executeScript', () => {
false, false,
false, false,
true, true,
defaultPollOptions, defaultPollStrategy,
true true
).catch((e: any) => e) ).catch((e: any) => e)
@@ -391,7 +391,7 @@ describe('executeScript', () => {
false, false,
false, false,
true, true,
defaultPollOptions, defaultPollStrategy,
true true
).catch((e: any) => e) ).catch((e: any) => e)
@@ -417,7 +417,7 @@ describe('executeScript', () => {
true, true,
false, false,
true, true,
defaultPollOptions, defaultPollStrategy,
true true
) )
@@ -442,7 +442,7 @@ describe('executeScript', () => {
false, false,
false, false,
true, true,
defaultPollOptions, defaultPollStrategy,
true true
) )
@@ -468,7 +468,7 @@ describe('executeScript', () => {
true, true,
false, false,
true, true,
defaultPollOptions, defaultPollStrategy,
true true
).catch((e: any) => e) ).catch((e: any) => e)
@@ -503,7 +503,7 @@ describe('executeScript', () => {
true, true,
false, false,
true, true,
defaultPollOptions, defaultPollStrategy,
true true
).catch((e: any) => e) ).catch((e: any) => e)
@@ -532,7 +532,7 @@ describe('executeScript', () => {
false, false,
true, true,
true, true,
defaultPollOptions, defaultPollStrategy,
true true
) )
@@ -563,7 +563,7 @@ describe('executeScript', () => {
false, false,
true, true,
true, true,
defaultPollOptions, defaultPollStrategy,
true true
).catch((e: any) => e) ).catch((e: any) => e)
@@ -597,7 +597,7 @@ describe('executeScript', () => {
false, false,
true, true,
true, true,
defaultPollOptions, defaultPollStrategy,
true true
) )
@@ -624,7 +624,7 @@ describe('executeScript', () => {
false, false,
true, true,
true, true,
defaultPollOptions, defaultPollStrategy,
true true
).catch((e: any) => e) ).catch((e: any) => e)

View File

@@ -7,14 +7,14 @@ import * as saveLogModule from '../saveLog'
import * as getFileStreamModule from '../getFileStream' import * as getFileStreamModule from '../getFileStream'
import * as isNodeModule from '../../../utils/isNode' import * as isNodeModule from '../../../utils/isNode'
import * as delayModule from '../../../utils/delay' import * as delayModule from '../../../utils/delay'
import { PollOptions } from '../../../types' import { PollStrategy, PollStrategies } from '../../../types'
import { WriteStream } from 'fs' import { WriteStream } from 'fs'
const baseUrl = 'http://localhost' const baseUrl = 'http://localhost'
const requestClient = new (<jest.Mock<RequestClient>>RequestClient)() const requestClient = new (<jest.Mock<RequestClient>>RequestClient)()
requestClient['httpClient'].defaults.baseURL = baseUrl requestClient['httpClient'].defaults.baseURL = baseUrl
const defaultPollOptions: PollOptions = { const defaultPollStrategy: PollStrategy = {
maxPollCount: 100, maxPollCount: 100,
pollInterval: 500, pollInterval: 500,
streamLog: false streamLog: false
@@ -32,7 +32,7 @@ describe('pollJobState', () => {
mockJob, mockJob,
false, false,
mockAuthConfig, mockAuthConfig,
defaultPollOptions defaultPollStrategy
) )
expect(getTokensModule.getTokens).toHaveBeenCalledWith( expect(getTokensModule.getTokens).toHaveBeenCalledWith(
@@ -47,7 +47,7 @@ describe('pollJobState', () => {
mockJob, mockJob,
false, false,
undefined, undefined,
defaultPollOptions defaultPollStrategy
) )
expect(getTokensModule.getTokens).not.toHaveBeenCalled() expect(getTokensModule.getTokens).not.toHaveBeenCalled()
@@ -59,7 +59,7 @@ describe('pollJobState', () => {
{ ...mockJob, links: mockJob.links.filter((l) => l.rel !== 'state') }, { ...mockJob, links: mockJob.links.filter((l) => l.rel !== 'state') },
false, false,
undefined, undefined,
defaultPollOptions defaultPollStrategy
).catch((e: any) => e) ).catch((e: any) => e)
expect((error as Error).message).toContain('Job state link was not found.') expect((error as Error).message).toContain('Job state link was not found.')
@@ -73,7 +73,7 @@ describe('pollJobState', () => {
mockJob, mockJob,
false, false,
mockAuthConfig, mockAuthConfig,
defaultPollOptions defaultPollStrategy
) )
expect(getTokensModule.getTokens).toHaveBeenCalledTimes(3) expect(getTokensModule.getTokens).toHaveBeenCalledTimes(3)
@@ -84,7 +84,7 @@ describe('pollJobState', () => {
const { saveLog } = require('../saveLog') const { saveLog } = require('../saveLog')
await pollJobState(requestClient, mockJob, false, mockAuthConfig, { await pollJobState(requestClient, mockJob, false, mockAuthConfig, {
...defaultPollOptions, ...defaultPollStrategy,
streamLog: true streamLog: true
}) })
@@ -97,7 +97,7 @@ describe('pollJobState', () => {
const { saveLog } = require('../saveLog') const { saveLog } = require('../saveLog')
await pollJobState(requestClient, mockJob, false, mockAuthConfig, { await pollJobState(requestClient, mockJob, false, mockAuthConfig, {
...defaultPollOptions, ...defaultPollStrategy,
streamLog: true streamLog: true
}) })
@@ -112,7 +112,7 @@ describe('pollJobState', () => {
const { getFileStream } = require('../getFileStream') const { getFileStream } = require('../getFileStream')
await pollJobState(requestClient, mockJob, false, mockAuthConfig, { await pollJobState(requestClient, mockJob, false, mockAuthConfig, {
...defaultPollOptions, ...defaultPollStrategy,
streamLog: true streamLog: true
}) })
@@ -128,7 +128,7 @@ describe('pollJobState', () => {
mockJob, mockJob,
false, false,
mockAuthConfig, mockAuthConfig,
defaultPollOptions defaultPollStrategy
) )
expect(saveLogModule.saveLog).not.toHaveBeenCalled() expect(saveLogModule.saveLog).not.toHaveBeenCalled()
@@ -137,18 +137,18 @@ describe('pollJobState', () => {
it('should return the current status when the max poll count is reached', async () => { it('should return the current status when the max poll count is reached', async () => {
mockRunningPoll() mockRunningPoll()
const pollOptions = { const pollStrategy = {
...defaultPollOptions, ...defaultPollStrategy,
maxPollCount: 1 maxPollCount: 1
} }
const pollStrategies = [pollOptions] const pollStrategies = [pollStrategy]
const state = await pollJobState( const state = await pollJobState(
requestClient, requestClient,
mockJob, mockJob,
false, false,
mockAuthConfig, mockAuthConfig,
pollOptions, pollStrategy,
pollStrategies pollStrategies
) )
@@ -164,7 +164,7 @@ describe('pollJobState', () => {
false, false,
mockAuthConfig, mockAuthConfig,
{ {
...defaultPollOptions, ...defaultPollStrategy,
maxPollCount: 200, maxPollCount: 200,
pollInterval: 10 pollInterval: 10
} }
@@ -181,7 +181,7 @@ describe('pollJobState', () => {
mockJob, mockJob,
false, false,
undefined, undefined,
defaultPollOptions defaultPollStrategy
) )
expect(requestClient.get).toHaveBeenCalledTimes(2) expect(requestClient.get).toHaveBeenCalledTimes(2)
@@ -197,7 +197,7 @@ describe('pollJobState', () => {
mockJob, mockJob,
true, true,
undefined, undefined,
defaultPollOptions defaultPollStrategy
) )
expect((process as any).logger.info).toHaveBeenCalledTimes(4) expect((process as any).logger.info).toHaveBeenCalledTimes(4)
@@ -227,7 +227,7 @@ describe('pollJobState', () => {
mockJob, mockJob,
false, false,
undefined, undefined,
defaultPollOptions defaultPollStrategy
) )
expect(requestClient.get).toHaveBeenCalledTimes(2) expect(requestClient.get).toHaveBeenCalledTimes(2)
@@ -242,7 +242,7 @@ describe('pollJobState', () => {
mockJob, mockJob,
false, false,
undefined, undefined,
defaultPollOptions defaultPollStrategy
).catch((e: any) => e) ).catch((e: any) => e)
expect(error.message).toEqual( expect(error.message).toEqual(
@@ -288,7 +288,7 @@ describe('pollJobState', () => {
'Poll strategies are not valid. No strategies provided.' 'Poll strategies are not valid. No strategies provided.'
) )
let pollStrategies: PollOptions[] = [] let pollStrategies: PollStrategies = []
await expect( await expect(
pollJobState( pollJobState(

View File

@@ -1,6 +1,8 @@
export interface PollOptions { export interface PollStrategy {
maxPollCount: number maxPollCount: number
pollInterval: number // milliseconds pollInterval: number // milliseconds
streamLog: boolean streamLog: boolean
logFolderPath?: string logFolderPath?: string
} }
export type PollStrategies = PollStrategy[]

View File

@@ -10,6 +10,6 @@ export * from './SASjsConfig'
export * from './SASjsRequest' export * from './SASjsRequest'
export * from './Session' export * from './Session'
export * from './UploadFile' export * from './UploadFile'
export * from './PollOptions' export * from './PollStrategy'
export * from './WriteStream' export * from './WriteStream'
export * from './ExecuteScript' export * from './ExecuteScript'