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

feat(start-compute-job): add API that starts a compute job and immediately returns the session

This commit is contained in:
Krishna Acondy
2020-10-06 09:21:15 +01:00
parent 08f58b5f4f
commit fd6905ea9f
2 changed files with 59 additions and 7 deletions

View File

@@ -153,6 +153,7 @@ export class SASViyaApiClient {
context.name, context.name,
accessToken, accessToken,
null, null,
true,
true true
).catch(() => null) ).catch(() => null)
}) })
@@ -425,7 +426,8 @@ export class SASViyaApiClient {
contextName: string, contextName: string,
accessToken?: string, accessToken?: string,
data = null, data = null,
expectWebout = false expectWebout = false,
waitForResult = true
): Promise<any> { ): Promise<any> {
try { try {
const headers: any = { const headers: any = {
@@ -509,6 +511,10 @@ export class SASViyaApiClient {
postJobRequest postJobRequest
) )
if (!waitForResult) {
return session
}
if (this.debug) { if (this.debug) {
console.log(`Job has been submitted for '${fileName}'.`) console.log(`Job has been submitted for '${fileName}'.`)
console.log( console.log(
@@ -592,7 +598,9 @@ export class SASViyaApiClient {
linesOfCode, linesOfCode,
contextName, contextName,
accessToken, accessToken,
data data,
false,
true
) )
} else { } else {
throw e throw e
@@ -909,9 +917,9 @@ export class SASViyaApiClient {
public async executeComputeJob( public async executeComputeJob(
sasJob: string, sasJob: string,
contextName: string, contextName: string,
debug: boolean,
data?: any, data?: any,
accessToken?: string accessToken?: string,
waitForResult = true
) { ) {
if (isRelativePath(sasJob) && !this.rootFolderName) { if (isRelativePath(sasJob) && !this.rootFolderName) {
throw new Error( throw new Error(
@@ -992,7 +1000,8 @@ export class SASViyaApiClient {
contextName, contextName,
accessToken, accessToken,
data, data,
true true,
waitForResult
) )
} }

View File

@@ -670,6 +670,48 @@ export default class SASjs {
) )
} }
/**
* Kicks off execution of the given job via the compute API.
* @returns an object representing the compute session created for the given job.
* @param sasJob - the path to the SAS program (ultimately resolves to
* the SAS `_program` parameter to run a Job Definition or SAS 9 Stored
* Process). Is prepended at runtime with the value of `appLoc`.
* @param data - a JSON object containing one or more tables to be sent to
* SAS. Can be `null` if no inputs required.
* @param config - provide any changes to the config here, for instance to
* enable/disable `debug`. Any change provided will override the global config,
* for that particular function call.
* @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.
*/
public async startComputeJob(
sasJob: string,
data: any,
config: any = {},
accessToken?: string
) {
config = {
...this.sasjsConfig,
...config
}
this.isMethodSupported('startComputeJob', ServerType.SASViya)
if (!config.contextName) {
throw new Error(
'Context name is undefined. Please set a `contextName` in your SASjs or override config.'
)
}
const waitForResult = false
return this.sasViyaApiClient?.executeComputeJob(
sasJob,
config.contextName,
data,
accessToken,
waitForResult
)
}
private async executeJobViaComputeApi( private async executeJobViaComputeApi(
sasJob: string, sasJob: string,
data: any, data: any,
@@ -689,13 +731,14 @@ export default class SASjs {
sasjsWaitingRequest.requestPromise.promise = new Promise( sasjsWaitingRequest.requestPromise.promise = new Promise(
async (resolve, reject) => { async (resolve, reject) => {
const waitForResult = true
this.sasViyaApiClient this.sasViyaApiClient
?.executeComputeJob( ?.executeComputeJob(
sasJob, sasJob,
config.contextName, config.contextName,
config.debug,
data, data,
accessToken accessToken,
waitForResult
) )
.then((response) => { .then((response) => {
if (!config.debug) { if (!config.debug) {