22 lines
605 B
JavaScript
22 lines
605 B
JavaScript
const { Queue } = require("bullmq")
|
|
const { getRedisConnectionOptions } = require("../services/redis/connection")
|
|
|
|
const connection = getRedisConnectionOptions()
|
|
const queue = new Queue("db-sync", { connection })
|
|
const DB_SYNC_REPEAT_MS = Math.max(2000, Number(process.env.DB_SYNC_REPEAT_MS) || 10000)
|
|
|
|
async function ensureDbSyncRepeatable() {
|
|
return queue.add(
|
|
"db-sync-batch",
|
|
{},
|
|
{
|
|
jobId: "db-sync-batch",
|
|
repeat: { every: DB_SYNC_REPEAT_MS },
|
|
removeOnComplete: true,
|
|
removeOnFail: 200,
|
|
}
|
|
)
|
|
}
|
|
|
|
module.exports = { queue, connection, ensureDbSyncRepeatable }
|