[backend] Set opts.removeOnComplete when discarding corrupt jobs (since the opts object is likely also corrupted)

This commit is contained in:
Laura Hausmann 2024-07-23 20:57:12 +02:00
parent 0d5220e505
commit cc9bc79466
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
5 changed files with 16 additions and 4 deletions

View file

@ -20,7 +20,10 @@ const logger = new Logger("deliver");
let latest: string | null = null; let latest: string | null = null;
export default async (job: Bull.Job<DeliverJobData>) => { export default async (job: Bull.Job<DeliverJobData>) => {
if (job.data == null || Object.keys(job.data).length === 0) return "Skip (data was null or empty)"; if (job.data == null || Object.keys(job.data).length === 0) {
job.opts.removeOnComplete = true;
return "Skip (data was null or empty)";
}
const { host } = new URL(job.data.to); const { host } = new URL(job.data.to);
const puny = toPuny(host); const puny = toPuny(host);

View file

@ -12,6 +12,7 @@ export async function endedPollNotification(
done: any, done: any,
): Promise<void> { ): Promise<void> {
if (job.data == null || Object.keys(job.data).length === 0) { if (job.data == null || Object.keys(job.data).length === 0) {
job.opts.removeOnComplete = true;
done(); done();
return; return;
} }

View file

@ -28,7 +28,10 @@ const logger = new Logger("inbox");
// Processing when an activity arrives in the user's inbox // Processing when an activity arrives in the user's inbox
export default async (job: Bull.Job<InboxJobData>): Promise<string> => { export default async (job: Bull.Job<InboxJobData>): Promise<string> => {
if (job.data == null || Object.keys(job.data).length === 0) return "Skip (data was null or empty)"; if (job.data == null || Object.keys(job.data).length === 0) {
job.opts.removeOnComplete = true;
return "Skip (data was null or empty)";
}
const signature = job.data.signature; // HTTP-signature const signature = job.data.signature; // HTTP-signature
let activity = job.data.activity; let activity = job.data.activity;

View file

@ -2,4 +2,6 @@ import Bull from "bull";
// Processor to be registered for jobs with __default__ (unnamed) handlers in queues that only have named handlers // Processor to be registered for jobs with __default__ (unnamed) handlers in queues that only have named handlers
// Prevents sporadic bogus jobs from clogging up the queues // Prevents sporadic bogus jobs from clogging up the queues
export async function noop(_: Bull.Job): Promise<void> { } export async function noop(job: Bull.Job): Promise<void> {
job.opts.removeOnComplete = true;
}

View file

@ -9,7 +9,10 @@ import config from "@/config/index.js";
const logger = new Logger("webhook"); const logger = new Logger("webhook");
export default async (job: Bull.Job<WebhookDeliverJobData>) => { export default async (job: Bull.Job<WebhookDeliverJobData>) => {
if (job.data == null || Object.keys(job.data).length === 0) return "Skip (data was null or empty)"; if (job.data == null || Object.keys(job.data).length === 0) {
job.opts.removeOnComplete = true;
return "Skip (data was null or empty)";
}
try { try {
logger.debug(`delivering ${job.data.webhookId}`); logger.debug(`delivering ${job.data.webhookId}`);