feat: Split off queue workers into a separate worker process

This commit is contained in:
Jesse Wierzbinski 2024-11-25 21:54:31 +01:00
parent 0b3e74107e
commit 1b98381242
No known key found for this signature in database
34 changed files with 987 additions and 676 deletions

View file

@ -0,0 +1,20 @@
import { Queue } from "bullmq";
import type { KnownEntity } from "~/types/api";
import { connection } from "~/utils/redis.ts";
export enum DeliveryJobType {
FederateEntity = "federateEntity",
}
export type DeliveryJobData = {
entity: KnownEntity;
recipientId: string;
senderId: string;
};
export const deliveryQueue = new Queue<DeliveryJobData, void, DeliveryJobType>(
"delivery",
{
connection,
},
);

17
classes/queues/fetch.ts Normal file
View file

@ -0,0 +1,17 @@
import { Queue } from "bullmq";
import { connection } from "~/utils/redis.ts";
export enum FetchJobType {
Instance = "instance",
User = "user",
Note = "user",
}
export type FetchJobData = {
uri: string;
refetcher?: string;
};
export const fetchQueue = new Queue<FetchJobData, void, FetchJobType>("fetch", {
connection,
});

31
classes/queues/inbox.ts Normal file
View file

@ -0,0 +1,31 @@
import type { Entity } from "@versia/federation/types";
import { Queue } from "bullmq";
import type { SocketAddress } from "bun";
import { connection } from "~/utils/redis.ts";
export enum InboxJobType {
ProcessEntity = "processEntity",
}
export type InboxJobData = {
data: Entity;
headers: {
"x-signature"?: string;
"x-nonce"?: string;
"x-signed-by"?: string;
authorization?: string;
};
request: {
url: string;
method: string;
body: string;
};
ip: SocketAddress | null;
};
export const inboxQueue = new Queue<InboxJobData, Response, InboxJobType>(
"inbox",
{
connection,
},
);