mirror of
https://github.com/versia-pub/server.git
synced 2026-04-27 20:59:15 +02:00
refactor(database): 🚚 Only import ORM abstractions from @versia/kit
This commit is contained in:
parent
f26493140f
commit
2f8b85a299
100 changed files with 150 additions and 154 deletions
51
worker.ts
Normal file
51
worker.ts
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import type { Entity } from "@versia/federation/types";
|
||||
import { Note } from "@versia/kit/db";
|
||||
import { Queue, Worker } from "bullmq";
|
||||
import IORedis from "ioredis";
|
||||
import { config } from "./packages/config-manager/index.ts";
|
||||
|
||||
const connection = new IORedis({
|
||||
host: config.redis.queue.host,
|
||||
port: config.redis.queue.port,
|
||||
password: config.redis.queue.password,
|
||||
db: config.redis.queue.database,
|
||||
});
|
||||
|
||||
enum DeliveryJobType {
|
||||
FederateNote = "federateNote",
|
||||
}
|
||||
|
||||
enum InboxJobType {
|
||||
ProcessEntity = "processEntity",
|
||||
}
|
||||
|
||||
const deliveryQueue = new Queue<{ noteId: string }, void, DeliveryJobType>(
|
||||
"delivery",
|
||||
{
|
||||
connection,
|
||||
},
|
||||
);
|
||||
|
||||
const inboxQueue = new Queue<{ data: Entity }, void, InboxJobType>("inbox", {
|
||||
connection,
|
||||
});
|
||||
|
||||
const worker = new Worker<{ noteId: string }, void, DeliveryJobType>(
|
||||
deliveryQueue.name,
|
||||
async (job) => {
|
||||
switch (job.name) {
|
||||
case DeliveryJobType.FederateNote: {
|
||||
const noteId = job.data.noteId;
|
||||
|
||||
const note = await Note.fromId(noteId);
|
||||
|
||||
if (!note) {
|
||||
throw new Error(`Note with ID ${noteId} not found`);
|
||||
}
|
||||
|
||||
await note.federateToUsers();
|
||||
}
|
||||
}
|
||||
},
|
||||
{ connection },
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue