From bc0fcba40c69824a991866e832beea65b77af36f Mon Sep 17 00:00:00 2001 From: unknown <89595418+unknownsrc@users.noreply.github.com> Date: Fri, 31 Mar 2023 16:17:37 +0200 Subject: [PATCH] channelQueue --- index.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 124cb54..2470c3d 100644 --- a/index.js +++ b/index.js @@ -15,6 +15,19 @@ const { PrismaClient } = require('@prisma/client') const prisma = new PrismaClient() const queue = new BQueue('download', { + prefix: 'download', + redis: { + host: process.env.REDIS_HOST, + port: process.env.REDIS_PORT, + password: process.env.REDIS_PASS, + }, + removeOnFailure: true, + removeOnSuccess: true, + storeJobs: false +}) + +const channelQueue = new BQueue('channel', { + prefix: 'channel', redis: { host: process.env.REDIS_HOST, port: process.env.REDIS_PORT, @@ -28,15 +41,14 @@ const queue = new BQueue('download', { async function check() { const channels = await prisma.autodownload.findMany() - for (c of channels) { + channels.forEach(async (c) => { if (await redis.get(c.channel)) { logger.info({ message: `${c.channel} is already being downloaded` }) } else { await redis.set(c.channel, 'downloading') - await checkChannel(c.channel) - await redis.del(c.channel) + channelQueue.createJob(c).save() } - } + }) } async function checkChannel(channelId) { @@ -107,6 +119,13 @@ queue.process(5, async function (job, done) { } }) +channelQueue.process(10, async function (job, done) { + const c = job.data + + await checkChannel(c.channel) + await redis.del(c.channel) +}) + setInterval(() => { check() }, 300000) \ No newline at end of file