From d527947182b3412b5bb566d78dc3a0312f577836 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Sun, 24 Nov 2024 22:28:29 +0100 Subject: [PATCH] fix(federation): :bug: Correctly handle job failures in inboxes --- api/users/:uuid/inbox/index.ts | 8 +++++++- worker.ts | 36 +++++++++++++--------------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/api/users/:uuid/inbox/index.ts b/api/users/:uuid/inbox/index.ts index 71c4f295..f8b6c6b2 100644 --- a/api/users/:uuid/inbox/index.ts +++ b/api/users/:uuid/inbox/index.ts @@ -116,12 +116,18 @@ export default apiRoute((app) => ip: context.env.ip ?? null, }); - return new Promise((resolve) => { + return new Promise((resolve, reject) => { inboxWorker.on("completed", (job) => { if (job.id === result.id) { resolve(job.returnvalue); } }); + + inboxWorker.on("failed", (job) => { + if (job && job.id === result.id) { + reject(job.returnvalue); + } + }); }); }), ); diff --git a/worker.ts b/worker.ts index ad3f5f75..9d653740 100644 --- a/worker.ts +++ b/worker.ts @@ -99,11 +99,9 @@ export const inboxWorker = new Worker( const logger = getLogger(["federation", "inbox"]); - logger.debug( - `Processing entity ${chalk.gray( - data.id, - )} from ${chalk.gray(signedBy)}`, - ); + logger.debug`Processing entity ${chalk.gray( + data.id, + )} from ${chalk.gray(signedBy)}`; if (authorization) { const processor = new InboxProcessor( @@ -119,11 +117,9 @@ export const inboxWorker = new Worker( ip, ); - logger.debug( - `Entity ${chalk.gray( - data.id, - )} is potentially from a bridge`, - ); + logger.debug`Entity ${chalk.gray( + data.id, + )} is potentially from a bridge`; return await processor.process(); } @@ -175,13 +171,11 @@ export const inboxWorker = new Worker( ); } - logger.debug( - `Entity ${chalk.gray( - data.id, - )} is from remote instance ${chalk.gray( - remoteInstance.data.baseUrl, - )}`, - ); + logger.debug`Entity ${chalk.gray( + data.id, + )} is from remote instance ${chalk.gray( + remoteInstance.data.baseUrl, + )}`; const processor = new InboxProcessor( request, @@ -198,11 +192,9 @@ export const inboxWorker = new Worker( const output = await processor.process(); - logger.debug( - `${chalk.green( - "✔", - )} Finished processing entity ${chalk.gray(data.id)}`, - ); + logger.debug`${chalk.green( + "✔", + )} Finished processing entity ${chalk.gray(data.id)}`; return output; }