Skip to content

Commit 3ff2be9

Browse files
committed
if process is active dont exit the process
1 parent 22fe42d commit 3ff2be9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

dalai/worker.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,12 @@ class ProgressManager {
147147

148148
// --- Worker ---
149149

150+
let ACTIVE_COUNT = 0
151+
150152
const worker = new Worker(
151153
QUEUE_NAME,
152154
async (job) => {
155+
ACTIVE_COUNT++
153156
const startTime = Date.now()
154157
const { s3Bucket, s3Key, outputBucket } = job.data || {}
155158

@@ -426,17 +429,19 @@ const worker = new Worker(
426429
logger.info(`Worker started. Listening to queue "${QUEUE_NAME}"...`)
427430

428431
worker.on('completed', (job, result) => {
432+
ACTIVE_COUNT--
429433
logger.info(`Job ${job.id} completed.`)
430434
})
431435

432436
worker.on('failed', (job, err) => {
437+
ACTIVE_COUNT--
433438
logger.error(`Job ${job?.id} failed:`, err)
434439
})
435440

436441
async function shutdown() {
437442
logger.info('Shutting down worker...')
438443
try {
439-
await worker.close()
444+
if (ACTIVE_COUNT <= 0) await worker.close()
440445
} catch { }
441446
process.exit(0)
442447
}

0 commit comments

Comments
 (0)