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,
});
return new Promise<Response>((resolve) => {
return new Promise<Response>((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);
}
});
});
}),
);

View file

@ -99,11 +99,9 @@ export const inboxWorker = new Worker<InboxJobData, Response, InboxJobType>(
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<InboxJobData, Response, InboxJobType>(
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<InboxJobData, Response, InboxJobType>(
);
}
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<InboxJobData, Response, InboxJobType>(
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;
}