chore: Move to Typescript (#2783)

This PR moves the entire project to Typescript. Due to the ~1000 ignores this will lead to a messy codebase for a while, but the churn is worth it – all of those ignore comments are places that were never type-safe previously.

closes #1282
This commit is contained in:
Tom Moor
2021-11-29 06:40:55 -08:00
committed by GitHub
parent 25ccfb5d04
commit 15b1069bcc
1017 changed files with 17410 additions and 54942 deletions

70
server/services/worker.ts Normal file
View File

@@ -0,0 +1,70 @@
import Logger from "@server/logging/logger";
import {
globalEventQueue,
processorEventQueue,
websocketsQueue,
emailsQueue,
} from "../queues";
import Backlinks from "../queues/processors/backlinks";
import Debouncer from "../queues/processors/debouncer";
import Emails from "../queues/processors/emails";
import Exports from "../queues/processors/exports";
import Imports from "../queues/processors/imports";
import Notifications from "../queues/processors/notifications";
import Revisions from "../queues/processors/revisions";
import Slack from "../queues/processors/slack";
const EmailsProcessor = new Emails();
const eventProcessors = {
backlinks: new Backlinks(),
debouncer: new Debouncer(),
imports: new Imports(),
exports: new Exports(),
notifications: new Notifications(),
revisions: new Revisions(),
slack: new Slack(),
};
export default function init() {
// this queue processes global events and hands them off to services
globalEventQueue.process(function (job) {
Object.keys(eventProcessors).forEach((name) => {
processorEventQueue.add({ ...job.data, service: name });
});
websocketsQueue.add(job.data);
});
processorEventQueue.process(function (job) {
const event = job.data;
const processor = eventProcessors[event.service];
if (!processor) {
Logger.warn(`Received event for processor that isn't registered`, event);
return;
}
if (processor.on) {
Logger.info("processor", `${event.service} processing ${event.name}`, {
name: event.name,
modelId: event.modelId,
});
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'error' implicitly has an 'any' type.
processor.on(event).catch((error) => {
Logger.error(
`Error processing ${event.name} in ${event.service}`,
error,
event
);
});
}
});
emailsQueue.process(function (job) {
const event = job.data;
EmailsProcessor.on(event).catch((error) => {
Logger.error(
`Error processing ${event.name} in emails processor`,
error,
event
);
});
});
}