mirror of
https://github.com/sasjs/server.git
synced 2026-01-15 01:40:05 +00:00
fix: recreate crashed session
This commit is contained in:
@@ -15,7 +15,7 @@ const app = express()
|
|||||||
const { MODE, CORS, PORT_WEB } = process.env
|
const { MODE, CORS, PORT_WEB } = process.env
|
||||||
const whiteList = [
|
const whiteList = [
|
||||||
`http://localhost:${PORT_WEB ?? 3000}`,
|
`http://localhost:${PORT_WEB ?? 3000}`,
|
||||||
'https://sas.analytium.co.uk:8343/'
|
'https://sas.analytium.co.uk:8343'
|
||||||
]
|
]
|
||||||
|
|
||||||
if (MODE?.trim() !== 'server' || CORS?.trim() === 'enable') {
|
if (MODE?.trim() !== 'server' || CORS?.trim() === 'enable') {
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ import {
|
|||||||
createFile,
|
createFile,
|
||||||
fileExists,
|
fileExists,
|
||||||
generateTimestamp,
|
generateTimestamp,
|
||||||
readFile
|
readFile,
|
||||||
|
moveFile
|
||||||
} from '@sasjs/utils'
|
} from '@sasjs/utils'
|
||||||
|
|
||||||
const execFilePromise = promisify(execFile)
|
const execFilePromise = promisify(execFile)
|
||||||
@@ -32,8 +33,9 @@ export class SessionController {
|
|||||||
return session
|
return session
|
||||||
}
|
}
|
||||||
|
|
||||||
private async createSession() {
|
private async createSession(): Promise<Session> {
|
||||||
const sessionId = generateUniqueFileName(generateTimestamp())
|
const sessionId = generateUniqueFileName(generateTimestamp())
|
||||||
|
console.log('creating session', sessionId)
|
||||||
const sessionFolder = path.join(getTmpSessionsFolderPath(), sessionId)
|
const sessionFolder = path.join(getTmpSessionsFolderPath(), sessionId)
|
||||||
|
|
||||||
const creationTimeStamp = sessionId.split('-').pop() as string
|
const creationTimeStamp = sessionId.split('-').pop() as string
|
||||||
@@ -100,25 +102,35 @@ 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
|
||||||
await this.waitForSession(session)
|
if (!(await this.waitForSession(session))) {
|
||||||
|
console.log('session is crashed', sessionId)
|
||||||
|
|
||||||
|
return this.createSession()
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('session is ready', sessionId)
|
||||||
return session
|
return session
|
||||||
}
|
}
|
||||||
|
|
||||||
public async waitForSession(session: Session) {
|
private async waitForSession(session: Session) {
|
||||||
const codeFilePath = path.join(session.path, 'code.sas')
|
const codeFilePath = path.join(session.path, 'code.sas')
|
||||||
|
|
||||||
// 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 || '')
|
console.log('session crashed?', !!session.crashed, session.crashed || '')
|
||||||
|
if (session.crashed) {
|
||||||
|
await this.deleteSession(session)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
session.ready = true
|
session.ready = true
|
||||||
return Promise.resolve(session)
|
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
|
||||||
await deleteFolder(session.path)
|
if (session.crashed) await moveFile(session.path, `${session.path}-crashed`)
|
||||||
|
else await deleteFolder(session.path)
|
||||||
|
|
||||||
// remove the session from the session array
|
// remove the session from the session array
|
||||||
if (session.ready) {
|
if (session.ready) {
|
||||||
|
|||||||
Reference in New Issue
Block a user