mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-24 10:57:30 -07:00
[backend] Discard jobs with null/undefined/empty data objects; add no-op handlers for invalid queue jobs
This stops corrupted/invalid jobs from clogging up the queue. Ref: https://github.com/OptimalBits/bull/issues/2461
This commit is contained in:
parent
a2eecc22d2
commit
0d5220e505
9 changed files with 24 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
||||||
import type Bull from "bull";
|
import type Bull from "bull";
|
||||||
|
import { noop } from "@/queue/processors/noop.js";
|
||||||
|
|
||||||
const jobs = {} as Record<string, Bull.ProcessCallbackFunction<Record<string, unknown>>>;
|
const jobs = {} as Record<string, Bull.ProcessCallbackFunction<Record<string, unknown>>>;
|
||||||
|
|
||||||
|
@ -6,4 +7,6 @@ export default function (q: Bull.Queue) {
|
||||||
for (const [k, v] of Object.entries(jobs)) {
|
for (const [k, v] of Object.entries(jobs)) {
|
||||||
q.process(k, 16, v);
|
q.process(k, 16, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
q.process(noop);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import { importMastoPost } from "./import-masto-post.js";
|
||||||
import { importCkPost } from "./import-firefish-post.js";
|
import { importCkPost } from "./import-firefish-post.js";
|
||||||
import { importBlocking } from "./import-blocking.js";
|
import { importBlocking } from "./import-blocking.js";
|
||||||
import { importCustomEmojis } from "./import-custom-emojis.js";
|
import { importCustomEmojis } from "./import-custom-emojis.js";
|
||||||
|
import { noop } from "@/queue/processors/noop.js";
|
||||||
|
|
||||||
const jobs = {
|
const jobs = {
|
||||||
deleteDriveFiles,
|
deleteDriveFiles,
|
||||||
|
@ -44,4 +45,6 @@ export default function (dbQueue: Bull.Queue<DbJobData>) {
|
||||||
for (const [k, v] of Object.entries(jobs)) {
|
for (const [k, v] of Object.entries(jobs)) {
|
||||||
dbQueue.process(k, v);
|
dbQueue.process(k, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dbQueue.process(noop);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ 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)";
|
||||||
const { host } = new URL(job.data.to);
|
const { host } = new URL(job.data.to);
|
||||||
const puny = toPuny(host);
|
const puny = toPuny(host);
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,10 @@ export async function endedPollNotification(
|
||||||
job: Bull.Job<EndedPollNotificationJobData>,
|
job: Bull.Job<EndedPollNotificationJobData>,
|
||||||
done: any,
|
done: any,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
if (job.data == null || Object.keys(job.data).length === 0) {
|
||||||
|
done();
|
||||||
|
return;
|
||||||
|
}
|
||||||
const note = await Notes.findOneBy({ id: job.data.noteId });
|
const note = await Notes.findOneBy({ id: job.data.noteId });
|
||||||
if (note == null || !note.hasPoll) {
|
if (note == null || !note.hasPoll) {
|
||||||
done();
|
done();
|
||||||
|
|
|
@ -28,6 +28,7 @@ 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)";
|
||||||
const signature = job.data.signature; // HTTP-signature
|
const signature = job.data.signature; // HTTP-signature
|
||||||
let activity = job.data.activity;
|
let activity = job.data.activity;
|
||||||
|
|
||||||
|
|
5
packages/backend/src/queue/processors/noop.ts
Normal file
5
packages/backend/src/queue/processors/noop.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
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> { }
|
|
@ -2,6 +2,7 @@ import type Bull from "bull";
|
||||||
import type { ObjectStorageJobData } from "@/queue/types.js";
|
import type { ObjectStorageJobData } from "@/queue/types.js";
|
||||||
import deleteFile from "./delete-file.js";
|
import deleteFile from "./delete-file.js";
|
||||||
import cleanRemoteFiles from "./clean-remote-files.js";
|
import cleanRemoteFiles from "./clean-remote-files.js";
|
||||||
|
import { noop } from "@/queue/processors/noop.js";
|
||||||
|
|
||||||
const jobs = {
|
const jobs = {
|
||||||
deleteFile,
|
deleteFile,
|
||||||
|
@ -16,4 +17,6 @@ export default function (q: Bull.Queue) {
|
||||||
for (const [k, v] of Object.entries(jobs)) {
|
for (const [k, v] of Object.entries(jobs)) {
|
||||||
q.process(k, 16, v);
|
q.process(k, 16, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
q.process(noop);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { checkExpiredMutings } from "./check-expired-mutings.js";
|
||||||
import { clean } from "./clean.js";
|
import { clean } from "./clean.js";
|
||||||
import { setLocalEmojiSizes } from "./local-emoji-size.js";
|
import { setLocalEmojiSizes } from "./local-emoji-size.js";
|
||||||
import { verifyLinks } from "./verify-links.js";
|
import { verifyLinks } from "./verify-links.js";
|
||||||
|
import { noop } from "@/queue/processors/noop.js";
|
||||||
|
|
||||||
const jobs = {
|
const jobs = {
|
||||||
tickCharts,
|
tickCharts,
|
||||||
|
@ -25,4 +26,6 @@ export default function (dbQueue: Bull.Queue<Record<string, unknown>>) {
|
||||||
for (const [k, v] of Object.entries(jobs)) {
|
for (const [k, v] of Object.entries(jobs)) {
|
||||||
dbQueue.process(k, v);
|
dbQueue.process(k, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dbQueue.process(noop);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ 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)";
|
||||||
try {
|
try {
|
||||||
logger.debug(`delivering ${job.data.webhookId}`);
|
logger.debug(`delivering ${job.data.webhookId}`);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue