Skip to content

Commit

Permalink
Merge pull request #594 from sasjs/issue-588
Browse files Browse the repository at this point in the history
fix: sas9JobExecutor issues
  • Loading branch information
allanbowe authored Dec 3, 2021
2 parents 0b795b2 + c9ecc1d commit 5a478c8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/SASjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,7 @@ export default class SASjs {
this.sasjsConfig.serverUrl,
this.sasjsConfig.serverType!,
this.jobsPath,
this.requestClient,
this.sasjsConfig.httpsAgentOptions
)

Expand Down
38 changes: 34 additions & 4 deletions src/job-execution/Sas9JobExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ErrorResponse } from '../types/errors'
import { convertToCSV, isRelativePath } from '../utils'
import { BaseJobExecutor } from './JobExecutor'
import { Sas9RequestClient } from '../request/Sas9RequestClient'
import { RequestClient } from '../request/RequestClient'

/**
* Job executor for SAS9 servers for use in Node.js environments.
Expand All @@ -13,15 +14,16 @@ import { Sas9RequestClient } from '../request/Sas9RequestClient'
* job execution requests.
*/
export class Sas9JobExecutor extends BaseJobExecutor {
private requestClient: Sas9RequestClient
private sas9RequestClient: Sas9RequestClient
constructor(
serverUrl: string,
serverType: ServerType,
private jobsPath: string,
private requestClient: RequestClient,
httpsAgentOptions?: https.AgentOptions
) {
super(serverUrl, serverType)
this.requestClient = new Sas9RequestClient(serverUrl, httpsAgentOptions)
this.sas9RequestClient = new Sas9RequestClient(serverUrl, httpsAgentOptions)
}

async execute(sasJob: string, data: any, config: any) {
Expand All @@ -37,6 +39,8 @@ export class Sas9JobExecutor extends BaseJobExecutor {
: ''
}`

apiUrl = `${apiUrl}${config.debug ? '&_debug=131' : ''}`

let requestParams = {
...this.getRequestParams(config)
}
Expand All @@ -49,6 +53,8 @@ export class Sas9JobExecutor extends BaseJobExecutor {
} catch (e: any) {
return Promise.reject(new ErrorResponse(e?.message, e))
}
} else {
data = ''
}

for (const key in requestParams) {
Expand All @@ -57,16 +63,18 @@ export class Sas9JobExecutor extends BaseJobExecutor {
}
}

await this.requestClient.login(
await this.sas9RequestClient.login(
config.username,
config.password,
this.jobsPath
)

const contentType =
data && Object.keys(data).length
? 'multipart/form-data; boundary=' + (formData as any)._boundary
: 'text/plain'
return await this.requestClient!.post(

return await this.sas9RequestClient!.post(
apiUrl,
formData,
undefined,
Expand All @@ -76,6 +84,28 @@ export class Sas9JobExecutor extends BaseJobExecutor {
Connection: 'Keep-Alive'
}
)
.then((res: any) => {
let resString = res

if (typeof res === 'object') {
resString = JSON.stringify(res)
}

this.requestClient!.appendRequest(resString, sasJob, config.debug)

return res
})
.catch((err: any) => {
let errString = err

if (typeof err === 'object') {
errString = JSON.stringify(errString)
}

this.requestClient!.appendRequest(errString, sasJob, config.debug)

return err
})
}

private getRequestParams(config: any): any {
Expand Down

1 comment on commit 5a478c8

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

Total coverage

Status Category Percentage Covered / Total
🔴 Statements 58.12% 1603/2758
🔴 Branches 39.55% 547/1383
🔴 Functions 45.63% 230/504
🟡 Lines 67.2% 2559/3808

Status of coverage: 🟢 - ok, 🟡 - slightly more than threshold, 🔴 - under the threshold

Report generated by 🧪jest coverage report action from 5a478c8

Please sign in to comment.