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

const connection = getRedisConnectionOptions()
const queue = new Queue("db-sync", { connection })

async function ensureDbSyncRepeatable() {
  return queue.add(
    "db-sync-batch",
    {},
    {
      jobId: "db-sync-batch",
      repeat: { every: 30000 },
      removeOnComplete: true,
      removeOnFail: 200,
    }
  )
}

module.exports = { queue, connection, ensureDbSyncRepeatable }
