mirror of
https://github.com/sasjs/server.git
synced 2026-01-05 05:40:06 +00:00
feat(execute): add macroVars to job execution
This commit is contained in:
@@ -3,14 +3,15 @@ import {
|
|||||||
readFile,
|
readFile,
|
||||||
generateTimestamp,
|
generateTimestamp,
|
||||||
deleteFile,
|
deleteFile,
|
||||||
fileExists
|
fileExists,
|
||||||
|
createFile
|
||||||
} from '@sasjs/utils'
|
} from '@sasjs/utils'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { ExecutionResult, ExecutionQuery } from '../types'
|
import { ExecutionResult, ExecutionQuery } from '../types'
|
||||||
import {
|
import {
|
||||||
getTmpFolderPath,
|
|
||||||
getTmpFilesFolderPath,
|
getTmpFilesFolderPath,
|
||||||
getTmpLogFolderPath
|
getTmpLogFolderPath,
|
||||||
|
getTmpWeboutFolderPath
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
import { configuration } from '../../package.json'
|
import { configuration } from '../../package.json'
|
||||||
|
|
||||||
@@ -27,11 +28,36 @@ export const processSas = async (
|
|||||||
|
|
||||||
const sasFile: string = sasCodePath.split(path.sep).pop() || 'default'
|
const sasFile: string = sasCodePath.split(path.sep).pop() || 'default'
|
||||||
|
|
||||||
|
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 sasLogPath = path.join(
|
const sasLogPath = path.join(
|
||||||
getTmpLogFolderPath(),
|
getTmpLogFolderPath(),
|
||||||
[sasFile.replace(/\.sas/g, ''), '-', generateTimestamp(), '.log'].join('')
|
[sasFile.replace(/\.sas/g, ''), '-', generateTimestamp(), '.log'].join('')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await createFile(sasLogPath, '')
|
||||||
|
|
||||||
execFile(
|
execFile(
|
||||||
configuration.sasPath,
|
configuration.sasPath,
|
||||||
['-SYSIN', sasCodePath, '-log', sasLogPath, '-nosplash'],
|
['-SYSIN', sasCodePath, '-log', sasLogPath, '-nosplash'],
|
||||||
@@ -41,7 +67,9 @@ export const processSas = async (
|
|||||||
|
|
||||||
const log = await readFile(sasLogPath)
|
const log = await readFile(sasLogPath)
|
||||||
|
|
||||||
// deleteFile(sasLogPath)
|
deleteFile(sasLogPath)
|
||||||
|
|
||||||
|
await createFile(sasCodePath, originalSasCode)
|
||||||
|
|
||||||
resolve({ log: log, logPath: sasLogPath })
|
resolve({ log: log, logPath: sasLogPath })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ router.post('/deploy', async (req, res) => {
|
|||||||
router.post('/execute', async (req, res) => {
|
router.post('/execute', async (req, res) => {
|
||||||
if (req.body?._program) {
|
if (req.body?._program) {
|
||||||
const result: ExecutionResult = await processSas(req.body)
|
const result: ExecutionResult = await processSas(req.body)
|
||||||
|
|
||||||
|
res.status(200).send(result)
|
||||||
} else {
|
} else {
|
||||||
res.status(400).send(`Please provide the location of SAS code`)
|
res.status(400).send(`Please provide the location of SAS code`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import { MacroVars } from '@sasjs/utils'
|
||||||
export interface ExecutionQuery {
|
export interface ExecutionQuery {
|
||||||
_program: string
|
_program: string
|
||||||
|
macroVars?: MacroVars
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isRequestQuery = (arg: any): arg is ExecutionQuery =>
|
export const isRequestQuery = (arg: any): arg is ExecutionQuery =>
|
||||||
|
|||||||
@@ -7,4 +7,7 @@ export const getTmpFolderPath = () =>
|
|||||||
export const getTmpFilesFolderPath = () =>
|
export const getTmpFilesFolderPath = () =>
|
||||||
path.join(getTmpFolderPath(), 'files')
|
path.join(getTmpFolderPath(), 'files')
|
||||||
|
|
||||||
export const getTmpLogFolderPath = () => path.join(getTmpFolderPath(), 'log')
|
export const getTmpLogFolderPath = () => path.join(getTmpFolderPath(), 'logs')
|
||||||
|
|
||||||
|
export const getTmpWeboutFolderPath = () =>
|
||||||
|
path.join(getTmpFolderPath(), 'webouts')
|
||||||
|
|||||||
Reference in New Issue
Block a user