mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-18 09:30:06 +00:00
fix(context): cache contexts after first request
This commit is contained in:
@@ -97,17 +97,14 @@ export class SASViyaApiClient {
|
|||||||
headers.Authorization = `Bearer ${accessToken}`;
|
headers.Authorization = `Bearer ${accessToken}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.contexts.length) {
|
const { result: contexts } = await this.request<{ items: Context[] }>(
|
||||||
const { result: contexts } = await this.request<{ items: Context[] }>(
|
`${this.serverUrl}/compute/contexts`,
|
||||||
`${this.serverUrl}/compute/contexts`,
|
{ headers }
|
||||||
{ headers }
|
);
|
||||||
);
|
const contextsList = contexts && contexts.items ? contexts.items : [];
|
||||||
|
|
||||||
this.contexts = contexts && contexts.items ? contexts.items : [];
|
|
||||||
}
|
|
||||||
const executableContexts: any[] = [];
|
const executableContexts: any[] = [];
|
||||||
|
|
||||||
const promises = this.contexts.map((context: any) => {
|
const promises = contextsList.map((context: any) => {
|
||||||
const linesOfCode = ["%put &=sysuserid;"];
|
const linesOfCode = ["%put &=sysuserid;"];
|
||||||
return this.executeScript(
|
return this.executeScript(
|
||||||
`test-${context.name}`,
|
`test-${context.name}`,
|
||||||
@@ -132,10 +129,10 @@ export class SASViyaApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
executableContexts.push({
|
executableContexts.push({
|
||||||
createdBy: this.contexts[index].createdBy,
|
createdBy: contextsList[index].createdBy,
|
||||||
id: this.contexts[index].id,
|
id: contextsList[index].id,
|
||||||
name: this.contexts[index].name,
|
name: contextsList[index].name,
|
||||||
version: this.contexts[index].version,
|
version: contextsList[index].version,
|
||||||
attributes: {
|
attributes: {
|
||||||
sysUserId,
|
sysUserId,
|
||||||
},
|
},
|
||||||
@@ -215,14 +212,20 @@ export class SASViyaApiClient {
|
|||||||
if (this.csrfToken) {
|
if (this.csrfToken) {
|
||||||
headers[this.csrfToken.headerName] = this.csrfToken.value;
|
headers[this.csrfToken.headerName] = this.csrfToken.value;
|
||||||
}
|
}
|
||||||
const { result: contexts } = await this.request<{ items: Context[] }>(
|
if (!this.contexts.length) {
|
||||||
`${this.serverUrl}/compute/contexts`,
|
const { result: contexts } = await this.request<{ items: Context[] }>(
|
||||||
{ headers }
|
`${this.serverUrl}/compute/contexts`,
|
||||||
|
{ headers }
|
||||||
|
);
|
||||||
|
|
||||||
|
this.contexts =
|
||||||
|
contexts && contexts.items && contexts.items.length
|
||||||
|
? contexts.items
|
||||||
|
: [];
|
||||||
|
}
|
||||||
|
const executionContext = this.contexts.find(
|
||||||
|
(c: any) => c.name === contextName
|
||||||
);
|
);
|
||||||
const executionContext =
|
|
||||||
contexts.items && contexts.items.length
|
|
||||||
? contexts.items.find((c: any) => c.name === contextName)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
if (executionContext) {
|
if (executionContext) {
|
||||||
// Request new session in context or use the ID passed in
|
// Request new session in context or use the ID passed in
|
||||||
@@ -345,7 +348,7 @@ export class SASViyaApiClient {
|
|||||||
console.error(
|
console.error(
|
||||||
`Unable to find execution context ${contextName}.\nPlease check the contextName in the tgtDeployVars and try again.`
|
`Unable to find execution context ${contextName}.\nPlease check the contextName in the tgtDeployVars and try again.`
|
||||||
);
|
);
|
||||||
console.error("Response from server: ", JSON.stringify(contexts));
|
console.error("Response from server: ", JSON.stringify(this.contexts));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user