mirror of
https://github.com/sasjs/server.git
synced 2026-01-06 22:20:06 +00:00
chore: debugging
This commit is contained in:
@@ -36,6 +36,7 @@ export class ExecutionController {
|
|||||||
const sessionController = getSessionController()
|
const sessionController = getSessionController()
|
||||||
|
|
||||||
const session = await sessionController.getSession()
|
const session = await sessionController.getSession()
|
||||||
|
console.log('using session', session.id)
|
||||||
session.inUse = true
|
session.inUse = true
|
||||||
|
|
||||||
const logPath = path.join(session.path, 'log.log')
|
const logPath = path.join(session.path, 'log.log')
|
||||||
@@ -97,13 +98,15 @@ ${program}`
|
|||||||
// (which can mean SAS trying to run a partial program, or
|
// (which can mean SAS trying to run a partial program, or
|
||||||
// failing due to file lock) we first create the file THEN
|
// failing due to file lock) we first create the file THEN
|
||||||
// we rename it.
|
// we rename it.
|
||||||
|
console.log('executing session', session.id)
|
||||||
await createFile(codePath + '.bkp', program)
|
await createFile(codePath + '.bkp', program)
|
||||||
await moveFile(codePath + '.bkp', codePath)
|
await moveFile(codePath + '.bkp', codePath)
|
||||||
|
|
||||||
// we now need to poll the session array
|
// we now need to poll the session status
|
||||||
while (!session.completed) {
|
while (!session.completed) {
|
||||||
await delay(50)
|
await delay(50)
|
||||||
}
|
}
|
||||||
|
console.log('completed session', session.id)
|
||||||
|
|
||||||
const log =
|
const log =
|
||||||
((await fileExists(logPath)) ? await readFile(logPath) : '') +
|
((await fileExists(logPath)) ? await readFile(logPath) : '') +
|
||||||
@@ -115,8 +118,8 @@ ${program}`
|
|||||||
const debugValue =
|
const debugValue =
|
||||||
typeof vars._debug === 'string' ? parseInt(vars._debug) : vars._debug
|
typeof vars._debug === 'string' ? parseInt(vars._debug) : vars._debug
|
||||||
|
|
||||||
|
// it should be deleted by scheduleSessionDestroy
|
||||||
session.inUse = false
|
session.inUse = false
|
||||||
sessionController.deleteSession(session)
|
|
||||||
|
|
||||||
if (returnJson) {
|
if (returnJson) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export class SessionController {
|
|||||||
private sessions: Session[] = []
|
private sessions: Session[] = []
|
||||||
|
|
||||||
public async getSession() {
|
public async getSession() {
|
||||||
const readySessions = this.sessions.filter((sess: Session) => sess.ready)
|
const readySessions = this.getReadySessions()
|
||||||
|
|
||||||
const session = readySessions.length
|
const session = readySessions.length
|
||||||
? readySessions[0]
|
? readySessions[0]
|
||||||
@@ -33,6 +33,9 @@ export class SessionController {
|
|||||||
return session
|
return session
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getReadySessions = (): Session[] =>
|
||||||
|
this.sessions.filter((sess: Session) => sess.ready)
|
||||||
|
|
||||||
private async createSession(): Promise<Session> {
|
private async createSession(): Promise<Session> {
|
||||||
const sessionId = generateUniqueFileName(generateTimestamp())
|
const sessionId = generateUniqueFileName(generateTimestamp())
|
||||||
console.log('creating session', sessionId)
|
console.log('creating session', sessionId)
|
||||||
@@ -102,13 +105,10 @@ export class SessionController {
|
|||||||
|
|
||||||
// SAS has been triggered but we can't use it until
|
// SAS has been triggered but we can't use it until
|
||||||
// the autoexec deletes the code.sas file
|
// the autoexec deletes the code.sas file
|
||||||
if (!(await this.waitForSession(session))) {
|
await this.waitForSession(session)
|
||||||
console.log('session is crashed', sessionId)
|
|
||||||
|
|
||||||
return this.createSession()
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('session is ready', sessionId)
|
console.log('session is ready', sessionId)
|
||||||
|
|
||||||
return session
|
return session
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,27 +117,21 @@ export class SessionController {
|
|||||||
|
|
||||||
// TODO: don't wait forever
|
// TODO: don't wait forever
|
||||||
while ((await fileExists(codeFilePath)) && !session.crashed) {}
|
while ((await fileExists(codeFilePath)) && !session.crashed) {}
|
||||||
console.log('session crashed?', !!session.crashed, session.crashed || '')
|
|
||||||
if (session.crashed) {
|
if (session.crashed)
|
||||||
await this.deleteSession(session)
|
console.log('session crashed! while waiting to be ready', session.crashed)
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
session.ready = true
|
session.ready = true
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deleteSession(session: Session) {
|
public async deleteSession(session: Session) {
|
||||||
// remove the temporary files, to avoid buildup
|
// remove the temporary files, to avoid buildup
|
||||||
if (session.crashed) await moveFile(session.path, `${session.path}-crashed`)
|
await deleteFolder(session.path)
|
||||||
else await deleteFolder(session.path)
|
|
||||||
|
|
||||||
// remove the session from the session array
|
// remove the session from the session array
|
||||||
if (session.ready) {
|
this.sessions = this.sessions.filter(
|
||||||
this.sessions = this.sessions.filter(
|
(sess: Session) => sess.id !== session.id
|
||||||
(sess: Session) => sess.id !== session.id
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private scheduleSessionDestroy(session: Session) {
|
private scheduleSessionDestroy(session: Session) {
|
||||||
|
|||||||
Reference in New Issue
Block a user