mirror of
https://github.com/sasjs/server.git
synced 2026-01-09 07:20:05 +00:00
feat(executor): response with webout
This commit is contained in:
@@ -29,29 +29,71 @@ export const processSas = async (
|
|||||||
|
|
||||||
const sasFile: string = sasCodePath.split(path.sep).pop() || 'default'
|
const sasFile: string = sasCodePath.split(path.sep).pop() || 'default'
|
||||||
|
|
||||||
const sasLogPath = path.join(
|
const logArgs = []
|
||||||
getTmpLogFolderPath(),
|
let sasLogPath
|
||||||
[sasFile.replace(/\.sas/g, ''), '-', generateTimestamp(), '.log'].join('')
|
|
||||||
|
if (query._debug) {
|
||||||
|
sasLogPath = path.join(
|
||||||
|
getTmpLogFolderPath(),
|
||||||
|
[sasFile.replace(/\.sas/g, ''), '-', generateTimestamp(), '.log'].join('')
|
||||||
|
)
|
||||||
|
logArgs.push('-log')
|
||||||
|
logArgs.push(sasLogPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
const sasWeboutPath = path.join(
|
||||||
|
getTmpWeboutFolderPath(),
|
||||||
|
[sasFile.replace(/\.sas/g, ''), '-', generateTimestamp(), '.json'].join('')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let sasCode = await readFile(sasCodePath)
|
||||||
|
const originalSasCode = sasCode
|
||||||
|
|
||||||
|
if (query.macroVars) {
|
||||||
|
const macroVars = query.macroVars.macroVars
|
||||||
|
|
||||||
|
Object.keys(macroVars).forEach(
|
||||||
|
(key: string) => (sasCode = `%let ${key}=${macroVars[key]};\n${sasCode}`)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
sasCode = `filename _webout "${sasWeboutPath}";\n${sasCode}`
|
||||||
|
|
||||||
|
await createFile(sasCodePath, sasCode)
|
||||||
|
|
||||||
const { stdout, stderr } = await execFilePromise(configuration.sasPath, [
|
const { stdout, stderr } = await execFilePromise(configuration.sasPath, [
|
||||||
'-SYSIN',
|
'-SYSIN',
|
||||||
sasCodePath,
|
sasCodePath,
|
||||||
'-log',
|
...logArgs,
|
||||||
sasLogPath,
|
|
||||||
'-nosplash'
|
'-nosplash'
|
||||||
])
|
])
|
||||||
|
|
||||||
if (stderr) return Promise.reject(stderr)
|
if (stderr) return Promise.reject(stderr)
|
||||||
|
|
||||||
if (await fileExists(sasLogPath)) {
|
if (await fileExists(sasWeboutPath)) {
|
||||||
return Promise.resolve({
|
const webout = await readFile(sasWeboutPath)
|
||||||
log: await readFile(sasLogPath),
|
|
||||||
logPath: sasLogPath
|
try {
|
||||||
})
|
const weboutJson = JSON.parse(webout)
|
||||||
|
|
||||||
|
if (sasLogPath && (await fileExists(sasLogPath))) {
|
||||||
|
return Promise.resolve({
|
||||||
|
webout: weboutJson,
|
||||||
|
log: await readFile(sasLogPath),
|
||||||
|
logPath: sasLogPath
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return Promise.resolve({
|
||||||
|
webout: weboutJson
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return Promise.reject(`Error while parsing Webout. Details: ${error}`)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return Promise.reject(`Log file wasn't created.`)
|
return Promise.reject(`Webout wasn't created.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// deleteFile(sasLogPath)
|
// await createFile(sasCodePath, originalSasCode)
|
||||||
|
// await deleteFile(sasLogPath)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,15 +48,34 @@ router.post('/deploy', async (req, res) => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
router.post('/execute', async (req, res) => {
|
// TODO: respond with HTML page including file tree
|
||||||
if (req.body?._program) {
|
router.get('/SASjsExecutor', async (req, res) => {
|
||||||
await processSas(req.body)
|
res.status(200).send({ status: 'success', tree: {} })
|
||||||
|
})
|
||||||
|
|
||||||
|
// SAS:
|
||||||
|
// https://sas.analytium.co.uk:8343/SASStoredProcess/do?_action=form,properties,execute,noba[…]blic%2Fapp%2Fdata-combiner%2Fservices%2Fcommon%2Fappinit
|
||||||
|
// https://sas.analytium.co.uk:8343/SASStoredProcess/
|
||||||
|
// https://sas.analytium.co.uk:8343/SASStoredProcess/do?&_program=%2FPublic%2Fapp%2Fdata-combiner%2Fservices%2Fcommon%2Fappinit&_DEBUG=131
|
||||||
|
// https://sas.analytium.co.uk:8343/SASStoredProcess/do?_program=%2FPublic%2Fapp%2Fdata-comb[…]ction=update%2Cnewwindow%2Cnobanner&_updatekey=895432774
|
||||||
|
|
||||||
|
// SASjs:
|
||||||
|
// http://localhost:5000/SASjsExecutor?_program=%2FPublic%2Fapp%2Fdata-combiner%2Fservices%2Fcommon%2Fappinit
|
||||||
|
// http://localhost:5000/SASjsExecutor
|
||||||
|
// http://localhost:5000/SASjsExecutor?_program=%2FPublic%2Fapp%2Fdata-combiner%2Fservices%2Fcommon%2Fappinit&_DEBUG=131
|
||||||
|
|
||||||
|
router.get('/SASjsExecutor/do', async (req, res) => {
|
||||||
|
const queryEntries = Object.keys(req.query).map((entry: string) =>
|
||||||
|
entry.toLowerCase()
|
||||||
|
)
|
||||||
|
const isDebug = queryEntries.find((entry: string) => entry === '_debug')
|
||||||
|
? true
|
||||||
|
: false
|
||||||
|
|
||||||
|
if (isRequestQuery(req.query)) {
|
||||||
|
await processSas({ ...req.query, _debug: isDebug })
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
res.status(200).send({
|
res.status(200).send(result)
|
||||||
status: 'success',
|
|
||||||
message: 'Job has been sent for execution.',
|
|
||||||
...result
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
res.status(400).send({
|
res.status(400).send({
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { MacroVars } from '@sasjs/utils'
|
|||||||
export interface ExecutionQuery {
|
export interface ExecutionQuery {
|
||||||
_program: string
|
_program: string
|
||||||
macroVars?: MacroVars
|
macroVars?: MacroVars
|
||||||
|
_debug?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isRequestQuery = (arg: any): arg is ExecutionQuery =>
|
export const isRequestQuery = (arg: any): arg is ExecutionQuery =>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export interface ExecutionResult {
|
export interface ExecutionResult {
|
||||||
log: string
|
webout: object
|
||||||
logPath: string
|
log?: string
|
||||||
|
logPath?: string
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user