mirror of
https://github.com/sasjs/server.git
synced 2026-01-07 06:30:06 +00:00
feat: compile systemInit and inject to autoExec
This commit is contained in:
@@ -18,10 +18,6 @@ export class ExecutionController {
|
||||
|
||||
let program = await readFile(programPath)
|
||||
|
||||
Object.keys(vars).forEach(
|
||||
(key: string) => (program = `%let ${key}=${vars[key]};\n${program}`)
|
||||
)
|
||||
|
||||
const sessionController = getSessionController()
|
||||
|
||||
const session = await sessionController.getSession()
|
||||
@@ -38,7 +34,12 @@ export class ExecutionController {
|
||||
preProgramVariables?.accessToken ?? 'accessToken'
|
||||
)
|
||||
|
||||
program = `
|
||||
const varStatments = Object.keys(vars).reduce(
|
||||
(computed: string, key: string) =>
|
||||
`${computed}%let ${key}=${vars[key]};\n`,
|
||||
''
|
||||
)
|
||||
const preProgramVarStatments = `
|
||||
%let _sasjs_tokenfile=${tokenFile};
|
||||
%let _sasjs_username=${preProgramVariables?.username};
|
||||
%let _sasjs_userid=${preProgramVariables?.userId};
|
||||
@@ -47,8 +48,17 @@ export class ExecutionController {
|
||||
%let _sasjs_apipath=/SASjsApi/stp/execute;
|
||||
%let _metaperson=&_sasjs_displayname;
|
||||
%let _metauser=&_sasjs_username;
|
||||
%let sasjsprocessmode=Stored Program;
|
||||
%let sasjsprocessmode=Stored Program;`
|
||||
|
||||
program = `
|
||||
/* runtime vars */
|
||||
${varStatments}
|
||||
filename _webout "${weboutPath}";
|
||||
|
||||
/* dynamic user-provided vars */
|
||||
${preProgramVarStatments}
|
||||
|
||||
/* actual job code */
|
||||
${program}`
|
||||
|
||||
// if no files are uploaded filesNamesMap will be undefined
|
||||
|
||||
@@ -2,12 +2,17 @@ import path from 'path'
|
||||
import { Session } from '../../types'
|
||||
import { promisify } from 'util'
|
||||
import { execFile } from 'child_process'
|
||||
import { getTmpSessionsFolderPath, generateUniqueFileName } from '../../utils'
|
||||
import {
|
||||
getTmpSessionsFolderPath,
|
||||
generateUniqueFileName,
|
||||
sysInitCompiledPath
|
||||
} from '../../utils'
|
||||
import {
|
||||
deleteFolder,
|
||||
createFile,
|
||||
fileExists,
|
||||
generateTimestamp
|
||||
generateTimestamp,
|
||||
readFile
|
||||
} from '@sasjs/utils'
|
||||
|
||||
const execFilePromise = promisify(execFile)
|
||||
@@ -52,9 +57,13 @@ export class SessionController {
|
||||
// we clean them up after a predefined period, if unused
|
||||
this.scheduleSessionDestroy(session)
|
||||
|
||||
// Place compiled system init code to autoexec
|
||||
const compiledSystemInitContent = await readFile(sysInitCompiledPath)
|
||||
|
||||
// the autoexec file is executed on SAS startup
|
||||
const autoExecPath = path.join(sessionFolder, 'autoexec.sas')
|
||||
await createFile(autoExecPath, autoExecContent)
|
||||
const contentForAutoExec = `/* compiled systemInit */\n${compiledSystemInitContent}\n/* autoexec */\n${autoExecContent}`
|
||||
await createFile(autoExecPath, contentForAutoExec)
|
||||
|
||||
// create empty code.sas as SAS will not start without a SYSIN
|
||||
const codePath = path.join(session.path, 'code.sas')
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
import { ExecutionController } from './internal'
|
||||
import { PreProgramVars } from '../types'
|
||||
import { getTmpFilesFolderPath, makeFilesNamesMap } from '../utils'
|
||||
import { request } from 'https'
|
||||
|
||||
interface ExecuteReturnJsonPayload {
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user