1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-08 13:00:05 +00:00

chore(refactor): split up and add tests for core functionality

This commit is contained in:
Krishna Acondy
2021-07-12 20:31:17 +01:00
parent f57c7b8f7d
commit 123b9fb535
14 changed files with 717 additions and 179 deletions

40
src/api/viya/saveLog.ts Normal file
View File

@@ -0,0 +1,40 @@
import { createFile } from '@sasjs/utils/file'
import { Job } from '../..'
import { RequestClient } from '../../request/RequestClient'
import { fetchLogByChunks } from '../../utils'
export async function saveLog(
job: Job,
requestClient: RequestClient,
shouldSaveLog: boolean,
logFilePath: string,
accessToken?: string
) {
if (!shouldSaveLog) {
return
}
if (!accessToken) {
throw new Error(
`Logs for job ${job.id} cannot be fetched without a valid access token.`
)
}
const logger = process.logger || console
const jobLogUrl = job.links.find((l) => l.rel === 'log')
if (!jobLogUrl) {
throw new Error(`Log URL for job ${job.id} was not found.`)
}
const logCount = job.logStatistics?.lineCount ?? 1000000
const log = await fetchLogByChunks(
requestClient,
accessToken,
`${jobLogUrl.href}/content`,
logCount
)
logger.info(`Writing logs to ${logFilePath}`)
await createFile(logFilePath, log)
}