import { Queue } from "bullmq";
import { redisConnection } from "../../lib/redis.js";
import { SIGNALS_QUEUE_NAME, SIGNALS_SNAPSHOT_JOB_NAME } from "./queue.constants.js";
import type { SignalsSnapshotJobData } from "./queue.types.js";

export const signalsQueue = new Queue<SignalsSnapshotJobData>(SIGNALS_QUEUE_NAME, {
  connection: redisConnection,
  defaultJobOptions: {
    attempts: 5,
    backoff: {
      type: "exponential",
      delay: 5_000
    },
    removeOnComplete: 200,
    removeOnFail: 500
  }
});

export async function enqueueSignalsSnapshot(payload: SignalsSnapshotJobData) {
  return signalsQueue.add(SIGNALS_SNAPSHOT_JOB_NAME, payload);
}
