diff --git a/lib/mq/executors.ts b/lib/mq/executors.ts index 88c22fb..5f822b0 100644 --- a/lib/mq/executors.ts +++ b/lib/mq/executors.ts @@ -18,23 +18,27 @@ const addJobToQueue = (failedCount: number, delay: number) => { failedCount: failedCount, }, }); - return; + return; }; export const insertVideosWorker = async (job: Job) => { const failedCount = (job.data.failedCount ?? 0) as number; const client = await db.connect(); - await executeTask(client, failedCount); - return; + try { + await executeTask(client, failedCount); + } finally { + client.release(); + } + return; }; const executeTask = async (client: Client, failedCount: number) => { logger.log("getLatestVideos now executing", "task"); const result = await insertLatestVideos(client); failedCount = result !== 0 ? truncate(failedCount + 1, 0, 5) : 0; - if (failedCount !== 0) { - addJobToQueue(failedCount, delayMap[failedCount] * MINUTE); - } - return; + if (failedCount !== 0) { + addJobToQueue(failedCount, delayMap[failedCount] * MINUTE); + } + return; };