[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;
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 puny = toPuny(host);

View File

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

View File

@ -28,7 +28,10 @@ const logger = new Logger("inbox");
// Processing when an activity arrives in the user's inbox
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
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
// 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");
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 {
logger.debug(`delivering ${job.data.webhookId}`);