fix: did not release DB connection after using it

This commit is contained in:
alikia2x (寒寒) 2025-02-09 23:29:33 +08:00
parent 1b714f1a84
commit e72e817152
Signed by: alikia2x
GPG Key ID: 56209E0CCD8420C6

View File

@ -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;
};