mirror of
https://github.com/sasjs/adapter.git
synced 2026-04-21 21:21:31 +00:00
chore(poll-job-status): renamed PollOptions to PollStrategy and added docs
This commit is contained in:
@@ -7,13 +7,13 @@ import * as uploadTablesModule from '../uploadTables'
|
||||
import * as getTokensModule from '../../../auth/getTokens'
|
||||
import * as formatDataModule from '../../../utils/formatDataForRequest'
|
||||
import * as fetchLogsModule from '../../../utils/fetchLogByChunks'
|
||||
import { PollOptions } from '../../../types'
|
||||
import { PollStrategy } from '../../../types'
|
||||
import { ComputeJobExecutionError, NotFoundError } from '../../../types/errors'
|
||||
import { Logger, LogLevel } from '@sasjs/utils'
|
||||
|
||||
const sessionManager = new (<jest.Mock<SessionManager>>SessionManager)()
|
||||
const requestClient = new (<jest.Mock<RequestClient>>RequestClient)()
|
||||
const defaultPollOptions: PollOptions = {
|
||||
const defaultPollStrategy: PollStrategy = {
|
||||
maxPollCount: 100,
|
||||
pollInterval: 500,
|
||||
streamLog: false
|
||||
@@ -98,7 +98,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
defaultPollOptions,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -126,7 +126,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
defaultPollOptions,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
).catch((e: any) => e)
|
||||
|
||||
@@ -152,7 +152,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
defaultPollOptions,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -176,7 +176,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
defaultPollOptions,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -202,7 +202,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
defaultPollOptions,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -248,7 +248,7 @@ describe('executeScript', () => {
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
defaultPollOptions,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -295,7 +295,7 @@ describe('executeScript', () => {
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
defaultPollOptions,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
).catch((e: any) => e)
|
||||
|
||||
@@ -315,7 +315,7 @@ describe('executeScript', () => {
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
defaultPollOptions,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -335,7 +335,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
defaultPollOptions,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -344,7 +344,7 @@ describe('executeScript', () => {
|
||||
mockJob,
|
||||
false,
|
||||
mockAuthConfig,
|
||||
defaultPollOptions
|
||||
defaultPollStrategy
|
||||
)
|
||||
})
|
||||
|
||||
@@ -365,7 +365,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
defaultPollOptions,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
).catch((e: any) => e)
|
||||
|
||||
@@ -391,7 +391,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
defaultPollOptions,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
).catch((e: any) => e)
|
||||
|
||||
@@ -417,7 +417,7 @@ describe('executeScript', () => {
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
defaultPollOptions,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -442,7 +442,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
defaultPollOptions,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -468,7 +468,7 @@ describe('executeScript', () => {
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
defaultPollOptions,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
).catch((e: any) => e)
|
||||
|
||||
@@ -503,7 +503,7 @@ describe('executeScript', () => {
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
defaultPollOptions,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
).catch((e: any) => e)
|
||||
|
||||
@@ -532,7 +532,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
defaultPollOptions,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -563,7 +563,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
defaultPollOptions,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
).catch((e: any) => e)
|
||||
|
||||
@@ -597,7 +597,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
defaultPollOptions,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -624,7 +624,7 @@ describe('executeScript', () => {
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
defaultPollOptions,
|
||||
defaultPollStrategy,
|
||||
true
|
||||
).catch((e: any) => e)
|
||||
|
||||
|
||||
@@ -7,14 +7,14 @@ import * as saveLogModule from '../saveLog'
|
||||
import * as getFileStreamModule from '../getFileStream'
|
||||
import * as isNodeModule from '../../../utils/isNode'
|
||||
import * as delayModule from '../../../utils/delay'
|
||||
import { PollOptions } from '../../../types'
|
||||
import { PollStrategy, PollStrategies } from '../../../types'
|
||||
import { WriteStream } from 'fs'
|
||||
|
||||
const baseUrl = 'http://localhost'
|
||||
const requestClient = new (<jest.Mock<RequestClient>>RequestClient)()
|
||||
requestClient['httpClient'].defaults.baseURL = baseUrl
|
||||
|
||||
const defaultPollOptions: PollOptions = {
|
||||
const defaultPollStrategy: PollStrategy = {
|
||||
maxPollCount: 100,
|
||||
pollInterval: 500,
|
||||
streamLog: false
|
||||
@@ -32,7 +32,7 @@ describe('pollJobState', () => {
|
||||
mockJob,
|
||||
false,
|
||||
mockAuthConfig,
|
||||
defaultPollOptions
|
||||
defaultPollStrategy
|
||||
)
|
||||
|
||||
expect(getTokensModule.getTokens).toHaveBeenCalledWith(
|
||||
@@ -47,7 +47,7 @@ describe('pollJobState', () => {
|
||||
mockJob,
|
||||
false,
|
||||
undefined,
|
||||
defaultPollOptions
|
||||
defaultPollStrategy
|
||||
)
|
||||
|
||||
expect(getTokensModule.getTokens).not.toHaveBeenCalled()
|
||||
@@ -59,7 +59,7 @@ describe('pollJobState', () => {
|
||||
{ ...mockJob, links: mockJob.links.filter((l) => l.rel !== 'state') },
|
||||
false,
|
||||
undefined,
|
||||
defaultPollOptions
|
||||
defaultPollStrategy
|
||||
).catch((e: any) => e)
|
||||
|
||||
expect((error as Error).message).toContain('Job state link was not found.')
|
||||
@@ -73,7 +73,7 @@ describe('pollJobState', () => {
|
||||
mockJob,
|
||||
false,
|
||||
mockAuthConfig,
|
||||
defaultPollOptions
|
||||
defaultPollStrategy
|
||||
)
|
||||
|
||||
expect(getTokensModule.getTokens).toHaveBeenCalledTimes(3)
|
||||
@@ -84,7 +84,7 @@ describe('pollJobState', () => {
|
||||
const { saveLog } = require('../saveLog')
|
||||
|
||||
await pollJobState(requestClient, mockJob, false, mockAuthConfig, {
|
||||
...defaultPollOptions,
|
||||
...defaultPollStrategy,
|
||||
streamLog: true
|
||||
})
|
||||
|
||||
@@ -97,7 +97,7 @@ describe('pollJobState', () => {
|
||||
const { saveLog } = require('../saveLog')
|
||||
|
||||
await pollJobState(requestClient, mockJob, false, mockAuthConfig, {
|
||||
...defaultPollOptions,
|
||||
...defaultPollStrategy,
|
||||
streamLog: true
|
||||
})
|
||||
|
||||
@@ -112,7 +112,7 @@ describe('pollJobState', () => {
|
||||
const { getFileStream } = require('../getFileStream')
|
||||
|
||||
await pollJobState(requestClient, mockJob, false, mockAuthConfig, {
|
||||
...defaultPollOptions,
|
||||
...defaultPollStrategy,
|
||||
streamLog: true
|
||||
})
|
||||
|
||||
@@ -128,7 +128,7 @@ describe('pollJobState', () => {
|
||||
mockJob,
|
||||
false,
|
||||
mockAuthConfig,
|
||||
defaultPollOptions
|
||||
defaultPollStrategy
|
||||
)
|
||||
|
||||
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 () => {
|
||||
mockRunningPoll()
|
||||
|
||||
const pollOptions = {
|
||||
...defaultPollOptions,
|
||||
const pollStrategy = {
|
||||
...defaultPollStrategy,
|
||||
maxPollCount: 1
|
||||
}
|
||||
const pollStrategies = [pollOptions]
|
||||
const pollStrategies = [pollStrategy]
|
||||
|
||||
const state = await pollJobState(
|
||||
requestClient,
|
||||
mockJob,
|
||||
false,
|
||||
mockAuthConfig,
|
||||
pollOptions,
|
||||
pollStrategy,
|
||||
pollStrategies
|
||||
)
|
||||
|
||||
@@ -164,7 +164,7 @@ describe('pollJobState', () => {
|
||||
false,
|
||||
mockAuthConfig,
|
||||
{
|
||||
...defaultPollOptions,
|
||||
...defaultPollStrategy,
|
||||
maxPollCount: 200,
|
||||
pollInterval: 10
|
||||
}
|
||||
@@ -181,7 +181,7 @@ describe('pollJobState', () => {
|
||||
mockJob,
|
||||
false,
|
||||
undefined,
|
||||
defaultPollOptions
|
||||
defaultPollStrategy
|
||||
)
|
||||
|
||||
expect(requestClient.get).toHaveBeenCalledTimes(2)
|
||||
@@ -197,7 +197,7 @@ describe('pollJobState', () => {
|
||||
mockJob,
|
||||
true,
|
||||
undefined,
|
||||
defaultPollOptions
|
||||
defaultPollStrategy
|
||||
)
|
||||
|
||||
expect((process as any).logger.info).toHaveBeenCalledTimes(4)
|
||||
@@ -227,7 +227,7 @@ describe('pollJobState', () => {
|
||||
mockJob,
|
||||
false,
|
||||
undefined,
|
||||
defaultPollOptions
|
||||
defaultPollStrategy
|
||||
)
|
||||
|
||||
expect(requestClient.get).toHaveBeenCalledTimes(2)
|
||||
@@ -242,7 +242,7 @@ describe('pollJobState', () => {
|
||||
mockJob,
|
||||
false,
|
||||
undefined,
|
||||
defaultPollOptions
|
||||
defaultPollStrategy
|
||||
).catch((e: any) => e)
|
||||
|
||||
expect(error.message).toEqual(
|
||||
@@ -288,7 +288,7 @@ describe('pollJobState', () => {
|
||||
'Poll strategies are not valid. No strategies provided.'
|
||||
)
|
||||
|
||||
let pollStrategies: PollOptions[] = []
|
||||
let pollStrategies: PollStrategies = []
|
||||
|
||||
await expect(
|
||||
pollJobState(
|
||||
|
||||
Reference in New Issue
Block a user