mirror of
https://github.com/sasjs/adapter.git
synced 2025-12-11 01:14:36 +00:00
fix(debug): propagate debug value from SASjs config
This commit is contained in:
@@ -38,6 +38,7 @@ export class SASViyaApiClient {
|
|||||||
|
|
||||||
private csrfToken: CsrfToken | null = null
|
private csrfToken: CsrfToken | null = null
|
||||||
private fileUploadCsrfToken: CsrfToken | null = null
|
private fileUploadCsrfToken: CsrfToken | null = null
|
||||||
|
private _debug = false
|
||||||
private sessionManager = new SessionManager(
|
private sessionManager = new SessionManager(
|
||||||
this.serverUrl,
|
this.serverUrl,
|
||||||
this.contextName,
|
this.contextName,
|
||||||
@@ -45,6 +46,15 @@ export class SASViyaApiClient {
|
|||||||
)
|
)
|
||||||
private folderMap = new Map<string, Job[]>()
|
private folderMap = new Map<string, Job[]>()
|
||||||
|
|
||||||
|
public get debug() {
|
||||||
|
return this._debug
|
||||||
|
}
|
||||||
|
|
||||||
|
public set debug(value: boolean) {
|
||||||
|
this._debug = value
|
||||||
|
this.sessionManager.debug = value
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of jobs in the currently set root folder.
|
* Returns a list of jobs in the currently set root folder.
|
||||||
*/
|
*/
|
||||||
@@ -140,7 +150,6 @@ export class SASViyaApiClient {
|
|||||||
linesOfCode,
|
linesOfCode,
|
||||||
context.name,
|
context.name,
|
||||||
accessToken,
|
accessToken,
|
||||||
false,
|
|
||||||
null,
|
null,
|
||||||
true
|
true
|
||||||
).catch(() => null)
|
).catch(() => null)
|
||||||
@@ -404,7 +413,6 @@ export class SASViyaApiClient {
|
|||||||
* @param contextName - the context to execute the code in.
|
* @param contextName - the context to execute the code in.
|
||||||
* @param accessToken - an access token for an authorized user.
|
* @param accessToken - an access token for an authorized user.
|
||||||
* @param sessionId - optional session ID to reuse.
|
* @param sessionId - optional session ID to reuse.
|
||||||
* @param silent - optional flag to disable logging.
|
|
||||||
* @param data - execution data.
|
* @param data - execution data.
|
||||||
* @param debug - when set to true, the log will be returned.
|
* @param debug - when set to true, the log will be returned.
|
||||||
* @param expectWebout - when set to true, the automatic _webout fileref will be checked for content, and that content returned. This fileref is used when the Job contains a SASjs web request (as opposed to executing arbitrary SAS code).
|
* @param expectWebout - when set to true, the automatic _webout fileref will be checked for content, and that content returned. This fileref is used when the Job contains a SASjs web request (as opposed to executing arbitrary SAS code).
|
||||||
@@ -414,12 +422,9 @@ export class SASViyaApiClient {
|
|||||||
linesOfCode: string[],
|
linesOfCode: string[],
|
||||||
contextName: string,
|
contextName: string,
|
||||||
accessToken?: string,
|
accessToken?: string,
|
||||||
silent = false,
|
|
||||||
data = null,
|
data = null,
|
||||||
debug = false,
|
|
||||||
expectWebout = false
|
expectWebout = false
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
silent = !debug
|
|
||||||
try {
|
try {
|
||||||
const headers: any = {
|
const headers: any = {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@@ -442,7 +447,7 @@ export class SASViyaApiClient {
|
|||||||
_OMITTEXTLOG: true
|
_OMITTEXTLOG: true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug) {
|
if (this.debug) {
|
||||||
jobArguments['_OMITTEXTLOG'] = false
|
jobArguments['_OMITTEXTLOG'] = false
|
||||||
jobArguments['_OMITSESSIONRESULTS'] = false
|
jobArguments['_OMITSESSIONRESULTS'] = false
|
||||||
jobArguments['_DEBUG'] = 131
|
jobArguments['_DEBUG'] = 131
|
||||||
@@ -502,7 +507,7 @@ export class SASViyaApiClient {
|
|||||||
postJobRequest
|
postJobRequest
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!silent) {
|
if (this.debug) {
|
||||||
console.log(`Job has been submitted for '${fileName}'.`)
|
console.log(`Job has been submitted for '${fileName}'.`)
|
||||||
console.log(
|
console.log(
|
||||||
`You can monitor the job progress at '${this.serverUrl}${
|
`You can monitor the job progress at '${this.serverUrl}${
|
||||||
@@ -511,12 +516,7 @@ export class SASViyaApiClient {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const jobStatus = await this.pollJobState(
|
const jobStatus = await this.pollJobState(postedJob, etag, accessToken)
|
||||||
postedJob,
|
|
||||||
etag,
|
|
||||||
accessToken,
|
|
||||||
silent
|
|
||||||
)
|
|
||||||
|
|
||||||
const { result: currentJob } = await this.request<Job>(
|
const { result: currentJob } = await this.request<Job>(
|
||||||
`${this.serverUrl}/compute/sessions/${executionSessionId}/jobs/${postedJob.id}`,
|
`${this.serverUrl}/compute/sessions/${executionSessionId}/jobs/${postedJob.id}`,
|
||||||
@@ -528,7 +528,7 @@ export class SASViyaApiClient {
|
|||||||
|
|
||||||
const logLink = currentJob.links.find((l) => l.rel === 'log')
|
const logLink = currentJob.links.find((l) => l.rel === 'log')
|
||||||
|
|
||||||
if (debug && logLink) {
|
if (this.debug && logLink) {
|
||||||
log = await this.request<any>(
|
log = await this.request<any>(
|
||||||
`${this.serverUrl}${logLink.href}/content?limit=10000`,
|
`${this.serverUrl}${logLink.href}/content?limit=10000`,
|
||||||
{
|
{
|
||||||
@@ -590,9 +590,7 @@ export class SASViyaApiClient {
|
|||||||
linesOfCode,
|
linesOfCode,
|
||||||
contextName,
|
contextName,
|
||||||
accessToken,
|
accessToken,
|
||||||
silent,
|
data
|
||||||
data,
|
|
||||||
debug
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
throw e
|
throw e
|
||||||
@@ -991,9 +989,7 @@ export class SASViyaApiClient {
|
|||||||
linesToExecute,
|
linesToExecute,
|
||||||
contextName,
|
contextName,
|
||||||
accessToken,
|
accessToken,
|
||||||
true,
|
|
||||||
data,
|
data,
|
||||||
debug,
|
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1125,12 +1121,7 @@ export class SASViyaApiClient {
|
|||||||
`${this.serverUrl}/jobExecution/jobs?_action=wait`,
|
`${this.serverUrl}/jobExecution/jobs?_action=wait`,
|
||||||
postJobRequest
|
postJobRequest
|
||||||
)
|
)
|
||||||
const jobStatus = await this.pollJobState(
|
const jobStatus = await this.pollJobState(postedJob, etag, accessToken)
|
||||||
postedJob,
|
|
||||||
etag,
|
|
||||||
accessToken,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
const { result: currentJob } = await this.request<Job>(
|
const { result: currentJob } = await this.request<Job>(
|
||||||
`${this.serverUrl}/jobExecution/jobs/${postedJob.id}`,
|
`${this.serverUrl}/jobExecution/jobs/${postedJob.id}`,
|
||||||
{ headers }
|
{ headers }
|
||||||
@@ -1195,8 +1186,7 @@ export class SASViyaApiClient {
|
|||||||
private async pollJobState(
|
private async pollJobState(
|
||||||
postedJob: any,
|
postedJob: any,
|
||||||
etag: string | null,
|
etag: string | null,
|
||||||
accessToken?: string,
|
accessToken?: string
|
||||||
silent = false
|
|
||||||
) {
|
) {
|
||||||
const MAX_POLL_COUNT = 1000
|
const MAX_POLL_COUNT = 1000
|
||||||
const POLL_INTERVAL = 100
|
const POLL_INTERVAL = 100
|
||||||
@@ -1235,7 +1225,7 @@ export class SASViyaApiClient {
|
|||||||
postedJobState === 'pending'
|
postedJobState === 'pending'
|
||||||
) {
|
) {
|
||||||
if (stateLink) {
|
if (stateLink) {
|
||||||
if (!silent) {
|
if (this.debug) {
|
||||||
console.log('Polling job status... \n')
|
console.log('Polling job status... \n')
|
||||||
}
|
}
|
||||||
const { result: jobState } = await this.request<string>(
|
const { result: jobState } = await this.request<string>(
|
||||||
@@ -1247,7 +1237,7 @@ export class SASViyaApiClient {
|
|||||||
)
|
)
|
||||||
|
|
||||||
postedJobState = jobState.trim()
|
postedJobState = jobState.trim()
|
||||||
if (!silent) {
|
if (this.debug) {
|
||||||
console.log(`Current state: ${postedJobState}\n`)
|
console.log(`Current state: ${postedJobState}\n`)
|
||||||
}
|
}
|
||||||
pollCount++
|
pollCount++
|
||||||
@@ -1263,49 +1253,6 @@ export class SASViyaApiClient {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private async waitForSession(
|
|
||||||
session: Session,
|
|
||||||
etag: string | null,
|
|
||||||
accessToken?: string,
|
|
||||||
silent = false
|
|
||||||
) {
|
|
||||||
let sessionState = session.state
|
|
||||||
let pollCount = 0
|
|
||||||
const headers: any = {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'If-None-Match': etag
|
|
||||||
}
|
|
||||||
if (accessToken) {
|
|
||||||
headers.Authorization = `Bearer ${accessToken}`
|
|
||||||
}
|
|
||||||
const stateLink = session.links.find((l: any) => l.rel === 'state')
|
|
||||||
return new Promise(async (resolve, _) => {
|
|
||||||
if (sessionState === 'pending') {
|
|
||||||
if (stateLink) {
|
|
||||||
if (!silent) {
|
|
||||||
console.log('Polling session status... \n')
|
|
||||||
}
|
|
||||||
const { result: state } = await this.request<string>(
|
|
||||||
`${this.serverUrl}${stateLink.href}?wait=30`,
|
|
||||||
{
|
|
||||||
headers
|
|
||||||
},
|
|
||||||
'text'
|
|
||||||
)
|
|
||||||
|
|
||||||
sessionState = state.trim()
|
|
||||||
if (!silent) {
|
|
||||||
console.log(`Current state: ${sessionState}\n`)
|
|
||||||
}
|
|
||||||
pollCount++
|
|
||||||
resolve(sessionState)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
resolve(sessionState)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private async uploadTables(data: any, accessToken?: string) {
|
private async uploadTables(data: any, accessToken?: string) {
|
||||||
const uploadedFiles = []
|
const uploadedFiles = []
|
||||||
const headers: any = {
|
const headers: any = {
|
||||||
|
|||||||
14
src/SASjs.ts
14
src/SASjs.ts
@@ -209,9 +209,7 @@ export default class SASjs {
|
|||||||
fileName: string,
|
fileName: string,
|
||||||
linesOfCode: string[],
|
linesOfCode: string[],
|
||||||
contextName: string,
|
contextName: string,
|
||||||
accessToken?: string,
|
accessToken?: string
|
||||||
sessionId = '',
|
|
||||||
silent = false
|
|
||||||
) {
|
) {
|
||||||
this.isMethodSupported('executeScriptSASViya', ServerType.SASViya)
|
this.isMethodSupported('executeScriptSASViya', ServerType.SASViya)
|
||||||
|
|
||||||
@@ -220,9 +218,7 @@ export default class SASjs {
|
|||||||
linesOfCode,
|
linesOfCode,
|
||||||
contextName,
|
contextName,
|
||||||
accessToken,
|
accessToken,
|
||||||
silent,
|
null
|
||||||
null,
|
|
||||||
this.sasjsConfig.debug
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -410,6 +406,9 @@ export default class SASjs {
|
|||||||
*/
|
*/
|
||||||
public setDebugState(value: boolean) {
|
public setDebugState(value: boolean) {
|
||||||
this.sasjsConfig.debug = value
|
this.sasjsConfig.debug = value
|
||||||
|
if (this.sasViyaApiClient) {
|
||||||
|
this.sasViyaApiClient.debug = value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -635,6 +634,7 @@ export default class SASjs {
|
|||||||
this.sasjsConfig.contextName,
|
this.sasjsConfig.contextName,
|
||||||
this.setCsrfTokenApi
|
this.setCsrfTokenApi
|
||||||
)
|
)
|
||||||
|
sasApiClient.debug = this.sasjsConfig.debug
|
||||||
} else if (this.sasjsConfig.serverType === ServerType.SAS9) {
|
} else if (this.sasjsConfig.serverType === ServerType.SAS9) {
|
||||||
sasApiClient = new SAS9ApiClient(serverUrl)
|
sasApiClient = new SAS9ApiClient(serverUrl)
|
||||||
}
|
}
|
||||||
@@ -1352,6 +1352,8 @@ export default class SASjs {
|
|||||||
this.sasjsConfig.contextName,
|
this.sasjsConfig.contextName,
|
||||||
this.setCsrfTokenApi
|
this.setCsrfTokenApi
|
||||||
)
|
)
|
||||||
|
|
||||||
|
this.sasViyaApiClient.debug = this.sasjsConfig.debug
|
||||||
}
|
}
|
||||||
if (this.sasjsConfig.serverType === ServerType.SAS9) {
|
if (this.sasjsConfig.serverType === ServerType.SAS9) {
|
||||||
if (this.sas9ApiClient)
|
if (this.sas9ApiClient)
|
||||||
|
|||||||
@@ -15,6 +15,15 @@ export class SessionManager {
|
|||||||
private sessions: Session[] = []
|
private sessions: Session[] = []
|
||||||
private currentContext: Context | null = null
|
private currentContext: Context | null = null
|
||||||
private csrfToken: CsrfToken | null = null
|
private csrfToken: CsrfToken | null = null
|
||||||
|
private _debug: boolean = false
|
||||||
|
|
||||||
|
public get debug() {
|
||||||
|
return this._debug
|
||||||
|
}
|
||||||
|
|
||||||
|
public set debug(value: boolean) {
|
||||||
|
this._debug = value
|
||||||
|
}
|
||||||
|
|
||||||
async getSession(accessToken?: string) {
|
async getSession(accessToken?: string) {
|
||||||
await this.createSessions(accessToken)
|
await this.createSessions(accessToken)
|
||||||
@@ -115,8 +124,7 @@ export class SessionManager {
|
|||||||
private async waitForSession(
|
private async waitForSession(
|
||||||
session: Session,
|
session: Session,
|
||||||
etag: string | null,
|
etag: string | null,
|
||||||
accessToken?: string,
|
accessToken?: string
|
||||||
silent = false
|
|
||||||
) {
|
) {
|
||||||
let sessionState = session.state
|
let sessionState = session.state
|
||||||
const headers: any = {
|
const headers: any = {
|
||||||
@@ -127,7 +135,7 @@ export class SessionManager {
|
|||||||
return new Promise(async (resolve, _) => {
|
return new Promise(async (resolve, _) => {
|
||||||
if (sessionState === 'pending') {
|
if (sessionState === 'pending') {
|
||||||
if (stateLink) {
|
if (stateLink) {
|
||||||
if (!silent) {
|
if (this.debug) {
|
||||||
console.log('Polling session status... \n') // ?
|
console.log('Polling session status... \n') // ?
|
||||||
}
|
}
|
||||||
const { result: state } = await this.request<string>(
|
const { result: state } = await this.request<string>(
|
||||||
@@ -139,7 +147,7 @@ export class SessionManager {
|
|||||||
)
|
)
|
||||||
|
|
||||||
sessionState = state.trim()
|
sessionState = state.trim()
|
||||||
if (!silent) {
|
if (this.debug) {
|
||||||
console.log(`Current state is '${sessionState}'\n`)
|
console.log(`Current state is '${sessionState}'\n`)
|
||||||
}
|
}
|
||||||
resolve(sessionState)
|
resolve(sessionState)
|
||||||
|
|||||||
Reference in New Issue
Block a user