mirror of https://github.com/preservetube/auto.git
channelQueue
This commit is contained in:
parent
c5df497d22
commit
bc0fcba40c
27
index.js
27
index.js
|
@ -15,6 +15,19 @@ const { PrismaClient } = require('@prisma/client')
|
||||||
const prisma = new PrismaClient()
|
const prisma = new PrismaClient()
|
||||||
|
|
||||||
const queue = new BQueue('download', {
|
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: {
|
redis: {
|
||||||
host: process.env.REDIS_HOST,
|
host: process.env.REDIS_HOST,
|
||||||
port: process.env.REDIS_PORT,
|
port: process.env.REDIS_PORT,
|
||||||
|
@ -28,15 +41,14 @@ const queue = new BQueue('download', {
|
||||||
async function check() {
|
async function check() {
|
||||||
const channels = await prisma.autodownload.findMany()
|
const channels = await prisma.autodownload.findMany()
|
||||||
|
|
||||||
for (c of channels) {
|
channels.forEach(async (c) => {
|
||||||
if (await redis.get(c.channel)) {
|
if (await redis.get(c.channel)) {
|
||||||
logger.info({ message: `${c.channel} is already being downloaded` })
|
logger.info({ message: `${c.channel} is already being downloaded` })
|
||||||
} else {
|
} else {
|
||||||
await redis.set(c.channel, 'downloading')
|
await redis.set(c.channel, 'downloading')
|
||||||
await checkChannel(c.channel)
|
channelQueue.createJob(c).save()
|
||||||
await redis.del(c.channel)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkChannel(channelId) {
|
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(() => {
|
setInterval(() => {
|
||||||
check()
|
check()
|
||||||
}, 300000)
|
}, 300000)
|
Loading…
Reference in New Issue