1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-09 05:20:05 +00:00

Compare commits

...

6 Commits

Author SHA1 Message Date
Yury Shkoda
ca18fcecf0 Merge pull request #167 from sasjs/cli-issue-249
feat(pollJobState): added ability to configure poll options
2020-11-30 12:55:11 +03:00
Yury Shkoda
009069169f chore(pollJobState): updated docs and added note 2020-11-30 12:45:37 +03:00
Yury Shkoda
6d166efd11 feat(pollJobState): made pollOptions optional and updated docs 2020-11-30 12:27:09 +03:00
Yury Shkoda
1b117a67aa feat(pollJobState): added ability to configure poll options 2020-11-30 10:21:49 +03:00
Yury Shkoda
505d85c256 Merge pull request #163 from sasjs/context-fix
fix(context): fixed result parsing
2020-11-26 13:36:07 +03:00
Yury Shkoda
71a3fe04a0 fix(context): fixed result parsing 2020-11-26 13:27:35 +03:00
4 changed files with 57 additions and 31 deletions

View File

@@ -17,7 +17,8 @@ import {
CsrfToken, CsrfToken,
EditContextInput, EditContextInput,
ErrorResponse, ErrorResponse,
JobDefinition JobDefinition,
PollOptions
} from './types' } from './types'
import { formatDataForRequest } from './utils/formatDataForRequest' import { formatDataForRequest } from './utils/formatDataForRequest'
import { SessionManager } from './SessionManager' import { SessionManager } from './SessionManager'
@@ -154,6 +155,7 @@ export class SASViyaApiClient {
context.name, context.name,
accessToken, accessToken,
null, null,
false,
true, true,
true true
).catch((err) => err) ).catch((err) => err)
@@ -164,30 +166,27 @@ export class SASViyaApiClient {
for (const promise of promises) results.push(await promise()) for (const promise of promises) results.push(await promise())
results.forEach((result: any, index: number) => { results.forEach((result: any, index: number) => {
if (result && result.error && result.error.details) { if (result && result.log) {
try { try {
const resultParsed = result.error.details const resultParsed = result.log
let sysUserId = ''
if (resultParsed && resultParsed.body) { const sysUserIdLog = resultParsed
let sysUserId = '' .split('\n')
.find((line: string) => line.startsWith('SYSUSERID='))
const sysUserIdLog = resultParsed.body if (sysUserIdLog) {
.split('\n') sysUserId = sysUserIdLog.replace('SYSUSERID=', '')
.find((line: string) => line.startsWith('SYSUSERID='))
if (sysUserIdLog) { executableContexts.push({
sysUserId = sysUserIdLog.replace('SYSUSERID=', '') createdBy: contextsList[index].createdBy,
id: contextsList[index].id,
executableContexts.push({ name: contextsList[index].name,
createdBy: contextsList[index].createdBy, version: contextsList[index].version,
id: contextsList[index].id, attributes: {
name: contextsList[index].name, sysUserId
version: contextsList[index].version, }
attributes: { })
sysUserId
}
})
}
} }
} catch (error) { } catch (error) {
throw error throw error
@@ -430,6 +429,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 }.
*/ */
public async executeScript( public async executeScript(
jobPath: string, jobPath: string,
@@ -439,7 +439,8 @@ export class SASViyaApiClient {
data = null, data = null,
debug: boolean = false, debug: boolean = false,
expectWebout = false, expectWebout = false,
waitForResult = true waitForResult = true,
pollOptions?: PollOptions
): Promise<any> { ): Promise<any> {
try { try {
const headers: any = { const headers: any = {
@@ -545,7 +546,12 @@ export class SASViyaApiClient {
) )
} }
const jobStatus = await this.pollJobState(postedJob, etag, accessToken) const jobStatus = await this.pollJobState(
postedJob,
etag,
accessToken,
pollOptions
)
const { result: currentJob } = await this.request<Job>( const { result: currentJob } = await this.request<Job>(
`${this.serverUrl}/compute/sessions/${executionSessionId}/jobs/${postedJob.id}`, `${this.serverUrl}/compute/sessions/${executionSessionId}/jobs/${postedJob.id}`,
@@ -951,6 +957,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 }.
*/ */
public async executeComputeJob( public async executeComputeJob(
sasJob: string, sasJob: string,
@@ -959,7 +966,8 @@ export class SASViyaApiClient {
data?: any, data?: any,
accessToken?: string, accessToken?: string,
waitForResult = true, waitForResult = true,
expectWebout = false expectWebout = false,
pollOptions?: PollOptions
) { ) {
if (isRelativePath(sasJob) && !this.rootFolderName) { if (isRelativePath(sasJob) && !this.rootFolderName) {
throw new Error( throw new Error(
@@ -1044,7 +1052,8 @@ export class SASViyaApiClient {
data, data,
debug, debug,
expectWebout, expectWebout,
waitForResult waitForResult,
pollOptions
) )
} }
@@ -1237,13 +1246,21 @@ export class SASViyaApiClient {
this.folderMap.set(path, itemsAtRoot) this.folderMap.set(path, itemsAtRoot)
} }
// REFACTOR: set default value for 'pollOptions' attribute
private async pollJobState( private async pollJobState(
postedJob: any, postedJob: any,
etag: string | null, etag: string | null,
accessToken?: string accessToken?: string,
pollOptions?: PollOptions
) { ) {
const MAX_POLL_COUNT = 1000 let POLL_INTERVAL = 100
const POLL_INTERVAL = 100 let MAX_POLL_COUNT = 1000
if (pollOptions) {
POLL_INTERVAL = pollOptions.POLL_INTERVAL || POLL_INTERVAL
MAX_POLL_COUNT = pollOptions.MAX_POLL_COUNT || MAX_POLL_COUNT
}
let postedJobState = '' let postedJobState = ''
let pollCount = 0 let pollCount = 0
const headers: any = { const headers: any = {

View File

@@ -32,7 +32,8 @@ import {
CsrfToken, CsrfToken,
UploadFile, UploadFile,
EditContextInput, EditContextInput,
ErrorResponse ErrorResponse,
PollOptions
} from './types' } from './types'
import { SASViyaApiClient } from './SASViyaApiClient' import { SASViyaApiClient } from './SASViyaApiClient'
import { SAS9ApiClient } from './SAS9ApiClient' import { SAS9ApiClient } from './SAS9ApiClient'
@@ -711,13 +712,15 @@ export default class SASjs {
* @param accessToken - a valid access token that is authorised to execute compute jobs. * @param accessToken - a valid access token that is 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 }.
*/ */
public async startComputeJob( public async startComputeJob(
sasJob: string, sasJob: string,
data: any, data: any,
config: any = {}, config: any = {},
accessToken?: string, accessToken?: string,
waitForResult?: boolean waitForResult?: boolean,
pollOptions?: PollOptions
) { ) {
config = { config = {
...this.sasjsConfig, ...this.sasjsConfig,
@@ -738,7 +741,8 @@ export default class SASjs {
data, data,
accessToken, accessToken,
!!waitForResult, !!waitForResult,
false false,
pollOptions
) )
} }

4
src/types/PollOptions.ts Normal file
View File

@@ -0,0 +1,4 @@
export interface PollOptions {
MAX_POLL_COUNT?: number
POLL_INTERVAL?: number
}

View File

@@ -12,3 +12,4 @@ export * from './SASjsWaitingRequest'
export * from './ServerType' export * from './ServerType'
export * from './Session' export * from './Session'
export * from './UploadFile' export * from './UploadFile'
export * from './PollOptions'