mirror of
https://github.com/outline/outline.git
synced 2026-04-24 11:20:11 -05:00
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:
@@ -0,0 +1,45 @@
|
||||
import Queue from "bull";
|
||||
import Redis from "ioredis";
|
||||
import { snakeCase } from "lodash";
|
||||
import Metrics from "@server/logging/metrics";
|
||||
import { client, subscriber } from "../redis";
|
||||
|
||||
export function createQueue(name: string) {
|
||||
const prefix = `queue.${snakeCase(name)}`;
|
||||
const queue = new Queue(name, {
|
||||
createClient(type) {
|
||||
switch (type) {
|
||||
case "client":
|
||||
return client;
|
||||
|
||||
case "subscriber":
|
||||
return subscriber;
|
||||
|
||||
default:
|
||||
return new Redis(process.env.REDIS_URL);
|
||||
}
|
||||
},
|
||||
|
||||
defaultJobOptions: {
|
||||
removeOnComplete: true,
|
||||
removeOnFail: true,
|
||||
},
|
||||
});
|
||||
queue.on("stalled", () => {
|
||||
Metrics.increment(`${prefix}.jobs.stalled`);
|
||||
});
|
||||
queue.on("completed", () => {
|
||||
Metrics.increment(`${prefix}.jobs.completed`);
|
||||
});
|
||||
queue.on("error", () => {
|
||||
Metrics.increment(`${prefix}.jobs.errored`);
|
||||
});
|
||||
queue.on("failed", () => {
|
||||
Metrics.increment(`${prefix}.jobs.failed`);
|
||||
});
|
||||
setInterval(async () => {
|
||||
Metrics.gauge(`${prefix}.count`, await queue.count());
|
||||
Metrics.gauge(`${prefix}.delayed_count`, await queue.getDelayedCount());
|
||||
}, 5 * 1000);
|
||||
return queue;
|
||||
}
|
||||
Reference in New Issue
Block a user