ref: wrap some worker functions with withDbConnection
This commit is contained in:
parent
4ee4d2ede9
commit
a9582722f4
@ -1,12 +1,9 @@
|
|||||||
import { Job } from "npm:bullmq@5.45.2";
|
import { Job } from "npm:bullmq@5.45.2";
|
||||||
import { db } from "db/init.ts";
|
|
||||||
import { collectSongs } from "mq/task/collectSongs.ts";
|
import { collectSongs } from "mq/task/collectSongs.ts";
|
||||||
|
import { withDbConnection } from "db/withConnection.ts";
|
||||||
|
import { Client } from "https://deno.land/x/postgres@v0.19.3/mod.ts";
|
||||||
|
|
||||||
export const collectSongsWorker = async (_job: Job): Promise<void> => {
|
export const collectSongsWorker = (_job: Job): Promise<void> =>
|
||||||
const client = await db.connect();
|
withDbConnection(async (client: Client) => {
|
||||||
try {
|
|
||||||
await collectSongs(client);
|
await collectSongs(client);
|
||||||
} finally {
|
});
|
||||||
client.release();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
export * from "mq/exec/getLatestVideos.ts";
|
export * from "mq/exec/getLatestVideos.ts";
|
||||||
export * from "./getVideoInfo.ts";
|
export * from "./getVideoInfo.ts";
|
||||||
export * from "./collectSongs.ts";
|
export * from "./collectSongs.ts";
|
||||||
|
export * from "./takeBulkSnapshot.ts";
|
@ -1,12 +1,10 @@
|
|||||||
import { Job } from "bullmq";
|
import { Job } from "bullmq";
|
||||||
import { queueLatestVideos } from "mq/task/queueLatestVideo.ts";
|
import { queueLatestVideos } from "mq/task/queueLatestVideo.ts";
|
||||||
import { db } from "db/init.ts";
|
import { withDbConnection } from "db/withConnection.ts";
|
||||||
|
import { Client } from "https://deno.land/x/postgres@v0.19.3/mod.ts";
|
||||||
|
|
||||||
export const getLatestVideosWorker = async (_job: Job): Promise<void> => {
|
|
||||||
const client = await db.connect();
|
export const getLatestVideosWorker = (_job: Job): Promise<void> =>
|
||||||
try {
|
withDbConnection(async (client: Client) => {
|
||||||
await queueLatestVideos(client);
|
await queueLatestVideos(client)
|
||||||
} finally {
|
});
|
||||||
client.release();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
import { Job } from "npm:bullmq@5.45.2";
|
import { Job } from "npm:bullmq@5.45.2";
|
||||||
import { db } from "db/init.ts";
|
|
||||||
import { insertVideoInfo } from "mq/task/getVideoDetails.ts";
|
import { insertVideoInfo } from "mq/task/getVideoDetails.ts";
|
||||||
|
import { withDbConnection } from "db/withConnection.ts";
|
||||||
|
import { Client } from "https://deno.land/x/postgres@v0.19.3/mod.ts";
|
||||||
|
import logger from "log/logger.ts";
|
||||||
|
|
||||||
export const getVideoInfoWorker = async (job: Job): Promise<number> => {
|
export const getVideoInfoWorker = async (job: Job): Promise<void> =>
|
||||||
const client = await db.connect();
|
await withDbConnection<void>(async (client: Client) => {
|
||||||
try {
|
|
||||||
const aid = job.data.aid;
|
const aid = job.data.aid;
|
||||||
if (!aid) {
|
if (!aid) {
|
||||||
return 3;
|
logger.warn("aid does not exists", "mq", "job:getVideoInfo");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
await insertVideoInfo(client, aid);
|
await insertVideoInfo(client, aid)
|
||||||
return 0;
|
});
|
||||||
} finally {
|
|
||||||
client.release();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
@ -12,7 +12,7 @@ import {
|
|||||||
snapshotTickWorker,
|
snapshotTickWorker,
|
||||||
takeSnapshotForVideoWorker,
|
takeSnapshotForVideoWorker,
|
||||||
} from "mq/exec/snapshotTick.ts";
|
} from "mq/exec/snapshotTick.ts";
|
||||||
import {takeBulkSnapshotForVideosWorker} from "../mq/exec/takeBulkSnapshot.ts";
|
import {takeBulkSnapshotForVideosWorker} from "mq/exec/executors.ts";
|
||||||
|
|
||||||
Deno.addSignalListener("SIGINT", async () => {
|
Deno.addSignalListener("SIGINT", async () => {
|
||||||
logger.log("SIGINT Received: Shutting down workers...", "mq");
|
logger.log("SIGINT Received: Shutting down workers...", "mq");
|
||||||
|
Loading…
Reference in New Issue
Block a user