1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-14 15:40:06 +00:00

fix(streamlog): use filepath if provided

This commit is contained in:
Krishna Acondy
2021-07-22 09:25:55 +01:00
parent c02eac196e
commit 0bb42c5e3c
4 changed files with 63 additions and 44 deletions

View File

@@ -5,7 +5,7 @@ import { RequestClient } from '../../request/RequestClient'
import { JobStatePollError } from '../../types/errors'
import { generateTimestamp } from '@sasjs/utils/time'
import { saveLog } from './saveLog'
import { createWriteStream } from '@sasjs/utils/file'
import { createWriteStream, isFolder } from '@sasjs/utils/file'
import { WriteStream } from 'fs'
import { Link } from '../../types'
@@ -53,12 +53,20 @@ export async function pollJobState(
let logFileStream
if (pollOptions?.streamLog) {
const logFileName = `${postedJob.name || 'job'}-${generateTimestamp()}.log`
const logFilePath = `${
pollOptions?.logFolderPath || process.cwd()
}/${logFileName}`
const logPath = pollOptions?.logFolderPath || process.cwd()
const isFolderPath = await isFolder(logPath)
if (isFolderPath) {
const logFileName = `${
postedJob.name || 'job'
}-${generateTimestamp()}.log`
const logFilePath = `${
pollOptions?.logFolderPath || process.cwd()
}/${logFileName}`
logFileStream = await createWriteStream(logFilePath)
logFileStream = await createWriteStream(logFilePath)
} else {
logFileStream = await createWriteStream(logPath)
}
}
let result = await doPoll(