Initial commit from Create Next App
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { Redis } from "ioredis";
|
||||
import { Queue } from "bullmq";
|
||||
import { QUEUE_NAME } from "./constants";
|
||||
import type { VideoJobData } from "./types";
|
||||
|
||||
let connection: Redis | null = null;
|
||||
let queue: Queue<VideoJobData> | null = null;
|
||||
|
||||
export function getRedisConnection(): Redis {
|
||||
if (!connection) {
|
||||
connection = new Redis(process.env.REDIS_URL || "redis://localhost:6379", {
|
||||
maxRetriesPerRequest: null,
|
||||
});
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
export function getVideoQueue(): Queue<VideoJobData> {
|
||||
if (!queue) {
|
||||
queue = new Queue<VideoJobData>(QUEUE_NAME, {
|
||||
connection: getRedisConnection(),
|
||||
});
|
||||
}
|
||||
return queue;
|
||||
}
|
||||
|
||||
export async function enqueueVideoJob(data: VideoJobData) {
|
||||
const q = getVideoQueue();
|
||||
await q.add("process-video", data, {
|
||||
attempts: 2,
|
||||
backoff: { type: "exponential", delay: 5000 },
|
||||
removeOnComplete: 100,
|
||||
removeOnFail: 200,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user