fix(federation): 🐛 Correctly handle job failures in inboxes

This commit is contained in:
Jesse Wierzbinski 2024-11-24 22:28:29 +01:00
parent c59ebef851
commit d527947182
No known key found for this signature in database
2 changed files with 21 additions and 23 deletions

View file

@ -116,12 +116,18 @@ export default apiRoute((app) =>
ip: context.env.ip ?? null, ip: context.env.ip ?? null,
}); });
return new Promise<Response>((resolve) => { return new Promise<Response>((resolve, reject) => {
inboxWorker.on("completed", (job) => { inboxWorker.on("completed", (job) => {
if (job.id === result.id) { if (job.id === result.id) {
resolve(job.returnvalue); resolve(job.returnvalue);
} }
}); });
inboxWorker.on("failed", (job) => {
if (job && job.id === result.id) {
reject(job.returnvalue);
}
});
}); });
}), }),
); );

View file

@ -99,11 +99,9 @@ export const inboxWorker = new Worker<InboxJobData, Response, InboxJobType>(
const logger = getLogger(["federation", "inbox"]); const logger = getLogger(["federation", "inbox"]);
logger.debug( logger.debug`Processing entity ${chalk.gray(
`Processing entity ${chalk.gray( data.id,
data.id, )} from ${chalk.gray(signedBy)}`;
)} from ${chalk.gray(signedBy)}`,
);
if (authorization) { if (authorization) {
const processor = new InboxProcessor( const processor = new InboxProcessor(
@ -119,11 +117,9 @@ export const inboxWorker = new Worker<InboxJobData, Response, InboxJobType>(
ip, ip,
); );
logger.debug( logger.debug`Entity ${chalk.gray(
`Entity ${chalk.gray( data.id,
data.id, )} is potentially from a bridge`;
)} is potentially from a bridge`,
);
return await processor.process(); return await processor.process();
} }
@ -175,13 +171,11 @@ export const inboxWorker = new Worker<InboxJobData, Response, InboxJobType>(
); );
} }
logger.debug( logger.debug`Entity ${chalk.gray(
`Entity ${chalk.gray( data.id,
data.id, )} is from remote instance ${chalk.gray(
)} is from remote instance ${chalk.gray( remoteInstance.data.baseUrl,
remoteInstance.data.baseUrl, )}`;
)}`,
);
const processor = new InboxProcessor( const processor = new InboxProcessor(
request, request,
@ -198,11 +192,9 @@ export const inboxWorker = new Worker<InboxJobData, Response, InboxJobType>(
const output = await processor.process(); const output = await processor.process();
logger.debug( logger.debug`${chalk.green(
`${chalk.green( "✔",
"✔", )} Finished processing entity ${chalk.gray(data.id)}`;
)} Finished processing entity ${chalk.gray(data.id)}`,
);
return output; return output;
} }