mirror of
https://github.com/sasjs/server.git
synced 2025-12-11 19:44:35 +00:00
feat: configure child process with writeStream to write logs to log file
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import { execFileSync } from 'child_process'
|
import { execFileSync } from 'child_process'
|
||||||
|
import { once } from 'stream'
|
||||||
import { getSASSessionController, getJSSessionController } from './'
|
import { getSASSessionController, getJSSessionController } from './'
|
||||||
import {
|
import {
|
||||||
readFile,
|
readFile,
|
||||||
@@ -121,9 +122,29 @@ export class ExecutionController {
|
|||||||
|
|
||||||
const codePath = path.join(session.path, 'code.js')
|
const codePath = path.join(session.path, 'code.js')
|
||||||
|
|
||||||
await createFile(codePath, program)
|
try {
|
||||||
|
await createFile(codePath, program)
|
||||||
|
|
||||||
execFileSync('node', [codePath])
|
// create a stream that will write to console outputs to log file
|
||||||
|
const writeStream = fs.createWriteStream(logPath)
|
||||||
|
|
||||||
|
// waiting for the open event so that we can have underlying file descriptor
|
||||||
|
await once(writeStream, 'open')
|
||||||
|
|
||||||
|
execFileSync('node', [codePath], {
|
||||||
|
stdio: ['ignore', writeStream, writeStream]
|
||||||
|
})
|
||||||
|
|
||||||
|
// copy the code.js program to log and end write stream
|
||||||
|
writeStream.end(program)
|
||||||
|
|
||||||
|
session.completed = true
|
||||||
|
console.log('session completed', session)
|
||||||
|
} catch (err: any) {
|
||||||
|
session.completed = true
|
||||||
|
session.crashed = err.toString()
|
||||||
|
console.log('session crashed', session.id, session.crashed)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
program = await this.createSASProgram(
|
program = await this.createSASProgram(
|
||||||
program,
|
program,
|
||||||
|
|||||||
Reference in New Issue
Block a user