1
0
Fork 0

adding check for running

pull/1700/head
Vallie Joseph 2024-03-28 17:30:06 +00:00
parent 18751738a8
commit bef1fc5f67
1 changed files with 24 additions and 15 deletions

View File

@ -7,6 +7,7 @@ import {UploadZipSpecification} from './upload-zip-specification'
import {getUploadChunkSize} from '../shared/config'
export const DEFAULT_COMPRESSION_LEVEL = 6
export var isRunning = false
// Custom stream transformer so we can set the highWaterMark property
// See https://github.com/nodejs/node/issues/8855
@ -27,6 +28,10 @@ export async function createZipUploadStream(
uploadSpecification: UploadZipSpecification[],
compressionLevel: number = DEFAULT_COMPRESSION_LEVEL
): Promise<ZipUploadStream> {
if (isRunning) {
throw new Error('The function is already running')
}
isRunning = true
core.debug(
`Creating Artifact archive with compressionLevel: ${compressionLevel}`
)
@ -40,7 +45,8 @@ export async function createZipUploadStream(
zip.on('finish', zipFinishCallback)
zip.on('end', zipEndCallback)
async.forEachOf(uploadSpecification, async file => {
try {
await async.forEachOf(uploadSpecification, async file => {
if (file.sourcePath !== null) {
zip.entry(
createReadStream(file.sourcePath),
@ -57,6 +63,9 @@ export async function createZipUploadStream(
})
}
})
} finally {
isRunning = false
}
const bufferSize = getUploadChunkSize()
const zipUploadStream = new ZipUploadStream(bufferSize)