mirror of
https://github.com/sasjs/server.git
synced 2026-01-11 00:10:06 +00:00
feat: add support for R stored programs
This commit is contained in:
@@ -231,9 +231,45 @@ export class PythonSessionController extends SessionController {
|
||||
}
|
||||
}
|
||||
|
||||
export class RSessionController extends SessionController {
|
||||
protected async createSession(): Promise<Session> {
|
||||
const sessionId = generateUniqueFileName(generateTimestamp())
|
||||
const sessionFolder = path.join(getSessionsFolder(), sessionId)
|
||||
|
||||
const creationTimeStamp = sessionId.split('-').pop() as string
|
||||
// death time of session is 15 mins from creation
|
||||
const deathTimeStamp = (
|
||||
parseInt(creationTimeStamp) +
|
||||
15 * 60 * 1000 -
|
||||
1000
|
||||
).toString()
|
||||
|
||||
const session: Session = {
|
||||
id: sessionId,
|
||||
ready: true,
|
||||
inUse: true,
|
||||
consumed: false,
|
||||
completed: false,
|
||||
creationTimeStamp,
|
||||
deathTimeStamp,
|
||||
path: sessionFolder
|
||||
}
|
||||
|
||||
const headersPath = path.join(session.path, 'stpsrv_header.txt')
|
||||
await createFile(headersPath, 'Content-type: text/plain')
|
||||
|
||||
this.sessions.push(session)
|
||||
return session
|
||||
}
|
||||
}
|
||||
|
||||
export const getSessionController = (
|
||||
runTime: RunTimeType
|
||||
): SASSessionController | JSSessionController | PythonSessionController => {
|
||||
):
|
||||
| SASSessionController
|
||||
| JSSessionController
|
||||
| PythonSessionController
|
||||
| RSessionController => {
|
||||
if (runTime === RunTimeType.SAS) {
|
||||
return getSASSessionController()
|
||||
}
|
||||
@@ -246,6 +282,10 @@ export const getSessionController = (
|
||||
return getPythonSessionController()
|
||||
}
|
||||
|
||||
if (runTime === RunTimeType.R) {
|
||||
return getRSessionController()
|
||||
}
|
||||
|
||||
throw new Error('No Runtime is configured')
|
||||
}
|
||||
|
||||
@@ -273,6 +313,14 @@ const getPythonSessionController = (): PythonSessionController => {
|
||||
return process.pythonSessionController
|
||||
}
|
||||
|
||||
const getRSessionController = (): RSessionController => {
|
||||
if (process.rSessionController) return process.rSessionController
|
||||
|
||||
process.rSessionController = new RSessionController()
|
||||
|
||||
return process.rSessionController
|
||||
}
|
||||
|
||||
const autoExecContent = `
|
||||
data _null_;
|
||||
/* remove the dummy SYSIN */
|
||||
|
||||
Reference in New Issue
Block a user