const { Queue } = require("bullmq")
const { getRedisConnectionOptions } = require("../services/redis/connection")

const connection = getRedisConnectionOptions()
const queue = new Queue("trendingdeal-list", { connection })

async function ensureTrendingDealListRepeatable() {
  return queue.add(
    "build-trendingdeal-list",
    {},
    {
      jobId: "trendingdeal-list-builder",
      repeat: { every: 30000 },
      removeOnComplete: true,
      removeOnFail: 100,
    }
  )
}

module.exports = { queue, connection, ensureTrendingDealListRepeatable }
