mirror of
https://github.com/sasjs/server.git
synced 2026-01-10 07:50:05 +00:00
chore(utils): add sleep util
This commit is contained in:
@@ -1,23 +1,14 @@
|
|||||||
import express from 'express'
|
import express from 'express'
|
||||||
import { processSas, createFileTree, getTreeExample } from '../controllers'
|
import { createFileTree, getTreeExample } from '../controllers'
|
||||||
import { ExecutionResult, isRequestQuery, isFileTree } from '../types'
|
import { ExecutionResult, isRequestQuery, isFileTree } from '../types'
|
||||||
|
import path from 'path'
|
||||||
|
import { getTmpFilesFolderPath } from '../utils'
|
||||||
|
import { ExecutionController } from '../controllers'
|
||||||
|
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
router.get('/', async (req, res) => {
|
router.get('/', async (_, res) => {
|
||||||
const query = req.query
|
res.status(200).send('Welcome to @sasjs/server API')
|
||||||
|
|
||||||
if (!isRequestQuery(query)) {
|
|
||||||
res.send('Welcome to @sasjs/server API')
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const result: ExecutionResult = await processSas(query)
|
|
||||||
|
|
||||||
res.send(`<b>Executed!</b><br>
|
|
||||||
<p>Log is located:</p> ${result.logPath}<br>
|
|
||||||
<p>Log:</p> <textarea style="width: 100%; height: 100%">${result.log}</textarea>`)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
router.post('/deploy', async (req, res) => {
|
router.post('/deploy', async (req, res) => {
|
||||||
@@ -54,20 +45,21 @@ router.get('/SASjsExecutor', async (req, res) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
router.get('/SASjsExecutor/do', async (req, res) => {
|
router.get('/SASjsExecutor/do', async (req, res) => {
|
||||||
const queryEntries = Object.keys(req.query).map((entry: string) =>
|
|
||||||
entry.toLowerCase()
|
|
||||||
)
|
|
||||||
|
|
||||||
if (isRequestQuery(req.query)) {
|
if (isRequestQuery(req.query)) {
|
||||||
await processSas({ ...req.query })
|
const sasCodePath = path
|
||||||
.then((result) => {
|
.join(getTmpFilesFolderPath(), req.query._program)
|
||||||
|
.replace(new RegExp('/', 'g'), path.sep)
|
||||||
|
|
||||||
|
await new ExecutionController()
|
||||||
|
.execute(sasCodePath, undefined, undefined, { ...req.query })
|
||||||
|
.then((result: {}) => {
|
||||||
res.status(200).send(result)
|
res.status(200).send(result)
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err: {} | string) => {
|
||||||
res.status(400).send({
|
res.status(400).send({
|
||||||
status: 'failure',
|
status: 'failure',
|
||||||
message: 'Job execution failed.',
|
message: 'Job execution failed.',
|
||||||
...err
|
...(typeof err === 'object' ? err : { details: err })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
3
src/utils/sleep.ts
Normal file
3
src/utils/sleep.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export const sleep = async (delay: number) => {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, delay))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user