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

Merge pull request #44 from sasjs/session-expiry-retry

fix(session-expiry-retry): retry job with new session on expiry
This commit is contained in:
Krishna Acondy
2020-08-18 21:45:47 +01:00
committed by GitHub
3 changed files with 147 additions and 122 deletions

View File

@@ -206,9 +206,9 @@ export class SASViyaApiClient {
silent = false,
data = null,
debug = false
) {
): Promise<any> {
silent = !debug;
try {
const headers: any = {
"Content-Type": "application/json",
};
@@ -311,7 +311,9 @@ export class SASViyaApiClient {
{
headers,
}
).then((res: any) => res.result.items.map((i: any) => i.line).join("\n"));
).then((res: any) =>
res.result.items.map((i: any) => i.line).join("\n")
);
}
if (jobStatus === "failed" || jobStatus === "error") {
@@ -332,12 +334,21 @@ export class SASViyaApiClient {
await this.sessionManager.clearSession(executionSessionId, accessToken);
return { result: jobResult?.result, log };
// } else {
// console.error(
// `Unable to find execution context ${contextName}.\nPlease check the contextName in the tgtDeployVars and try again.`
// );
// console.error("Response from server: ", JSON.stringify(this.contexts));
// }
} catch (e) {
if (e && e.status === 404) {
return this.executeScript(
jobName,
linesOfCode,
contextName,
accessToken,
silent,
data,
debug
);
} else {
throw e;
}
}
}
/**

View File

@@ -17,6 +17,16 @@ export class SessionManager {
await this.createSessions(accessToken);
this.createAndWaitForSession(accessToken);
const session = this.sessions.pop();
const secondsSinceSessionCreation =
(new Date().getTime() - new Date(session!.creationTimeStamp).getTime()) /
1000;
if (
secondsSinceSessionCreation >= session!.attributes.sessionInactiveTimeout
) {
await this.createSessions(accessToken);
const freshSession = this.sessions.pop();
return freshSession;
}
return session;
}

View File

@@ -4,4 +4,8 @@ export interface Session {
id: string;
state: string;
links: Link[];
attributes: {
sessionInactiveTimeout: number;
};
creationTimeStamp: string;
}