From 451f2dfaca84328fae70bef8b2c5dc10dbde5f86 Mon Sep 17 00:00:00 2001 From: Yury Shkoda Date: Mon, 4 Sep 2023 18:55:59 +0300 Subject: [PATCH] fix(execute-script): fixed executing jobs on viya using compute api --- jest.config.js | 6 +++--- src/api/viya/executeScript.ts | 27 +++++++++---------------- src/api/viya/spec/executeScript.spec.ts | 18 ++--------------- 3 files changed, 14 insertions(+), 37 deletions(-) diff --git a/jest.config.js b/jest.config.js index 47bd7db..1c34830 100644 --- a/jest.config.js +++ b/jest.config.js @@ -43,10 +43,10 @@ module.exports = { // An object that configures minimum threshold enforcement for coverage results coverageThreshold: { global: { - statements: 63.66, - branches: 44.74, + statements: 63.61, + branches: 44.72, functions: 53.94, - lines: 64.12 + lines: 64.07 } }, diff --git a/src/api/viya/executeScript.ts b/src/api/viya/executeScript.ts index 502a2b1..d025d1d 100644 --- a/src/api/viya/executeScript.ts +++ b/src/api/viya/executeScript.ts @@ -15,6 +15,10 @@ import { formatDataForRequest } from '../../utils/formatDataForRequest' import { pollJobState, JobState } from './pollJobState' import { uploadTables } from './uploadTables' +interface JobRequestBody { + [key: string]: number | string | string[] +} + /** * Executes code on the current SAS Viya server. * @param jobPath - the path to the file being submitted for execution. @@ -46,6 +50,7 @@ export async function executeScript( variables?: MacroVar ): Promise { let access_token = (authConfig || {}).access_token + if (authConfig) { ;({ access_token } = await getTokens(requestClient, authConfig)) } @@ -85,20 +90,6 @@ export async function executeScript( } } - const jobArguments: { [key: string]: any } = { - _contextName: contextName, - _OMITJSONLISTING: true, - _OMITJSONLOG: true, - _OMITSESSIONRESULTS: true, - _OMITTEXTLISTING: true, - _OMITTEXTLOG: true - } - - if (debug) { - jobArguments['_OMITTEXTLOG'] = false - jobArguments['_OMITSESSIONRESULTS'] = false - } - let fileName if (isRelativePath(jobPath)) { @@ -107,6 +98,7 @@ export async function executeScript( }` } else { const jobPathParts = jobPath.split('/') + fileName = jobPathParts.pop() } @@ -118,7 +110,6 @@ export async function executeScript( } if (variables) jobVariables = { ...jobVariables, ...variables } - if (debug) jobVariables = { ...jobVariables, _DEBUG: 131 } let files: any[] = [] @@ -145,12 +136,12 @@ export async function executeScript( } // Execute job in session - const jobRequestBody = { - name: fileName, + const jobRequestBody: JobRequestBody = { + name: fileName || 'Default Job Name', description: 'Powered by SASjs', code: linesOfCode, variables: jobVariables, - arguments: jobArguments + version: 2 } const { result: postedJob, etag } = await requestClient diff --git a/src/api/viya/spec/executeScript.spec.ts b/src/api/viya/spec/executeScript.spec.ts index 39a08d8..ca8de96 100644 --- a/src/api/viya/spec/executeScript.spec.ts +++ b/src/api/viya/spec/executeScript.spec.ts @@ -217,14 +217,7 @@ describe('executeScript', () => { sasjs_tables: 'foo', sasjs0data: 'bar' }, - arguments: { - _contextName: 'test context', - _OMITJSONLISTING: true, - _OMITJSONLOG: true, - _OMITSESSIONRESULTS: true, - _OMITTEXTLISTING: true, - _OMITTEXTLOG: true - } + version: 2 }, mockAuthConfig.access_token ) @@ -264,14 +257,7 @@ describe('executeScript', () => { sasjs0data: 'bar', _DEBUG: 131 }, - arguments: { - _contextName: 'test context', - _OMITJSONLISTING: true, - _OMITJSONLOG: true, - _OMITSESSIONRESULTS: false, - _OMITTEXTLISTING: true, - _OMITTEXTLOG: false - } + version: 2 }, mockAuthConfig.access_token )