mirror of
https://github.com/sasjs/adapter.git
synced 2025-12-11 09:24:35 +00:00
fix(*): cache job definition code after first fetch, make initial state request before poll
This commit is contained in:
@@ -675,20 +675,30 @@ export class SASViyaApiClient {
|
|||||||
const jobName = sasJob.split("/")[1];
|
const jobName = sasJob.split("/")[1];
|
||||||
const jobFolder = this.rootFolderMap.get(folderName);
|
const jobFolder = this.rootFolderMap.get(folderName);
|
||||||
const jobToExecute = jobFolder?.find((item) => item.name === jobName);
|
const jobToExecute = jobFolder?.find((item) => item.name === jobName);
|
||||||
const jobDefinitionLink = jobToExecute?.links.find(
|
if (!jobToExecute) {
|
||||||
(l) => l.rel === "getResource"
|
throw new Error("Job was not found.");
|
||||||
);
|
|
||||||
if (!jobDefinitionLink) {
|
|
||||||
console.error("Job definition URI was not found.");
|
|
||||||
throw new Error("Job definition URI was not found.");
|
|
||||||
}
|
}
|
||||||
const { result: jobDefinition } = await this.request<JobDefinition>(
|
|
||||||
`${this.serverUrl}${jobDefinitionLink.href}`,
|
let code = jobToExecute?.code;
|
||||||
headers
|
if (!code) {
|
||||||
);
|
const jobDefinitionLink = jobToExecute?.links.find(
|
||||||
const linesToExecute = jobDefinition.code
|
(l) => l.rel === "getResource"
|
||||||
.replace(/\r\n/g, "\n")
|
);
|
||||||
.split("\n");
|
if (!jobDefinitionLink) {
|
||||||
|
console.error("Job definition URI was not found.");
|
||||||
|
throw new Error("Job definition URI was not found.");
|
||||||
|
}
|
||||||
|
const { result: jobDefinition } = await this.request<JobDefinition>(
|
||||||
|
`${this.serverUrl}${jobDefinitionLink.href}`,
|
||||||
|
headers
|
||||||
|
);
|
||||||
|
|
||||||
|
code = jobDefinition.code;
|
||||||
|
|
||||||
|
// Add code to existing job definition
|
||||||
|
jobToExecute.code = code;
|
||||||
|
}
|
||||||
|
const linesToExecute = code.replace(/\r\n/g, "\n").split("\n");
|
||||||
return await this.executeScript(
|
return await this.executeScript(
|
||||||
sasJob,
|
sasJob,
|
||||||
linesToExecute,
|
linesToExecute,
|
||||||
@@ -928,6 +938,23 @@ export class SASViyaApiClient {
|
|||||||
headers.Authorization = `Bearer ${accessToken}`;
|
headers.Authorization = `Bearer ${accessToken}`;
|
||||||
}
|
}
|
||||||
const stateLink = postedJob.links.find((l: any) => l.rel === "state");
|
const stateLink = postedJob.links.find((l: any) => l.rel === "state");
|
||||||
|
if (!stateLink) {
|
||||||
|
Promise.reject("Job state link was not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
const { result: state } = await this.request<string>(
|
||||||
|
`${this.serverUrl}${stateLink.href}?_action=wait&wait=30`,
|
||||||
|
{
|
||||||
|
headers
|
||||||
|
},
|
||||||
|
"text"
|
||||||
|
);
|
||||||
|
|
||||||
|
const currentState = state.trim();
|
||||||
|
if (currentState === "completed") {
|
||||||
|
return Promise.resolve(currentState);
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise(async (resolve, _) => {
|
return new Promise(async (resolve, _) => {
|
||||||
const interval = setInterval(async () => {
|
const interval = setInterval(async () => {
|
||||||
if (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user