Handle promise linting (#5488)
This commit is contained in:
@@ -18,7 +18,7 @@ export default function init() {
|
||||
// Just give everything time to startup before running the first time. Not
|
||||
// _technically_ required to function.
|
||||
setTimeout(() => {
|
||||
run(TaskSchedule.Daily);
|
||||
run(TaskSchedule.Hourly);
|
||||
void run(TaskSchedule.Daily);
|
||||
void run(TaskSchedule.Hourly);
|
||||
}, 30 * Second);
|
||||
}
|
||||
|
||||
@@ -57,8 +57,8 @@ if (env.CDN_URL) {
|
||||
defaultSrc.push(env.CDN_URL);
|
||||
}
|
||||
|
||||
export default function init(app: Koa = new Koa(), server?: Server): Koa {
|
||||
initI18n();
|
||||
export default function init(app: Koa = new Koa(), server?: Server) {
|
||||
void initI18n();
|
||||
|
||||
if (isProduction) {
|
||||
// Force redirect to HTTPS protocol unless explicitly disabled
|
||||
|
||||
@@ -130,23 +130,27 @@ export default function init(
|
||||
|
||||
// Handle events from event queue that should be sent to the clients down ws
|
||||
const websockets = new WebsocketsProcessor();
|
||||
websocketQueue.process(
|
||||
traceFunction({
|
||||
serviceName: "websockets",
|
||||
spanName: "process",
|
||||
isRoot: true,
|
||||
})(async function (job) {
|
||||
const event = job.data;
|
||||
websocketQueue
|
||||
.process(
|
||||
traceFunction({
|
||||
serviceName: "websockets",
|
||||
spanName: "process",
|
||||
isRoot: true,
|
||||
})(async function (job) {
|
||||
const event = job.data;
|
||||
|
||||
Tracing.setResource(`Processor.WebsocketsProcessor`);
|
||||
Tracing.setResource(`Processor.WebsocketsProcessor`);
|
||||
|
||||
websockets.perform(event, io).catch((error) => {
|
||||
Logger.error("Error processing websocket event", error, {
|
||||
event,
|
||||
websockets.perform(event, io).catch((error) => {
|
||||
Logger.error("Error processing websocket event", error, {
|
||||
event,
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
})
|
||||
)
|
||||
.catch((err) => {
|
||||
Logger.fatal("Error starting websocketQueue", err);
|
||||
});
|
||||
}
|
||||
|
||||
async function authenticated(io: IO.Server, socket: SocketWithAuth) {
|
||||
@@ -168,9 +172,6 @@ async function authenticated(io: IO.Server, socket: SocketWithAuth) {
|
||||
rooms.push(`collection-${collectionId}`)
|
||||
);
|
||||
|
||||
// join all of the rooms at once
|
||||
socket.join(rooms);
|
||||
|
||||
// allow the client to request to join rooms
|
||||
socket.on("join", async (event) => {
|
||||
// user is joining a collection channel, because their permissions have
|
||||
@@ -194,6 +195,9 @@ async function authenticated(io: IO.Server, socket: SocketWithAuth) {
|
||||
Metrics.increment("websockets.collections.leave");
|
||||
}
|
||||
});
|
||||
|
||||
// join all of the rooms at once
|
||||
await socket.join(rooms);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,128 +12,144 @@ import processors from "../queues/processors";
|
||||
import tasks from "../queues/tasks";
|
||||
|
||||
export default function init() {
|
||||
initI18n();
|
||||
void initI18n();
|
||||
|
||||
// This queue processes the global event bus
|
||||
globalEventQueue.process(
|
||||
traceFunction({
|
||||
serviceName: "worker",
|
||||
spanName: "process",
|
||||
isRoot: true,
|
||||
})(async function (job) {
|
||||
const event = job.data;
|
||||
let err;
|
||||
globalEventQueue
|
||||
.process(
|
||||
traceFunction({
|
||||
serviceName: "worker",
|
||||
spanName: "process",
|
||||
isRoot: true,
|
||||
})(async function (job) {
|
||||
const event = job.data;
|
||||
let err;
|
||||
|
||||
setResource(`Event.${event.name}`);
|
||||
setResource(`Event.${event.name}`);
|
||||
|
||||
Logger.info("worker", `Processing ${event.name}`, {
|
||||
event,
|
||||
attempt: job.attemptsMade,
|
||||
});
|
||||
Logger.info("worker", `Processing ${event.name}`, {
|
||||
event,
|
||||
attempt: job.attemptsMade,
|
||||
});
|
||||
|
||||
// For each registered processor we check to see if it wants to handle the
|
||||
// event (applicableEvents), and if so add a new queued job specifically
|
||||
// for that processor.
|
||||
for (const name in processors) {
|
||||
// For each registered processor we check to see if it wants to handle the
|
||||
// event (applicableEvents), and if so add a new queued job specifically
|
||||
// for that processor.
|
||||
for (const name in processors) {
|
||||
const ProcessorClass = processors[name];
|
||||
|
||||
if (!ProcessorClass) {
|
||||
throw new Error(
|
||||
`Received event "${event.name}" for processor (${name}) that isn't registered. Check the file name matches the class name.`
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
if (name === "WebsocketsProcessor") {
|
||||
// websockets are a special case on their own queue because they must
|
||||
// only be consumed by the websockets service rather than workers.
|
||||
await websocketQueue.add(job.data);
|
||||
} else if (
|
||||
ProcessorClass.applicableEvents.includes(event.name) ||
|
||||
ProcessorClass.applicableEvents.includes("*")
|
||||
) {
|
||||
await processorEventQueue.add({ event, name });
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.error(
|
||||
`Error adding ${event.name} to ${name} queue`,
|
||||
error,
|
||||
event
|
||||
);
|
||||
err = error;
|
||||
}
|
||||
}
|
||||
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
)
|
||||
.catch((err) => {
|
||||
Logger.fatal("Error starting globalEventQueue", err);
|
||||
});
|
||||
|
||||
// Jobs for individual processors are processed here. Only applicable events
|
||||
// as unapplicable events were filtered in the global event queue above.
|
||||
processorEventQueue
|
||||
.process(
|
||||
traceFunction({
|
||||
serviceName: "worker",
|
||||
spanName: "process",
|
||||
isRoot: true,
|
||||
})(async function (job) {
|
||||
const { event, name } = job.data;
|
||||
const ProcessorClass = processors[name];
|
||||
|
||||
setResource(`Processor.${name}`);
|
||||
|
||||
if (!ProcessorClass) {
|
||||
throw new Error(
|
||||
`Received event "${event.name}" for processor (${name}) that isn't registered. Check the file name matches the class name.`
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
if (name === "WebsocketsProcessor") {
|
||||
// websockets are a special case on their own queue because they must
|
||||
// only be consumed by the websockets service rather than workers.
|
||||
await websocketQueue.add(job.data);
|
||||
} else if (
|
||||
ProcessorClass.applicableEvents.includes(event.name) ||
|
||||
ProcessorClass.applicableEvents.includes("*")
|
||||
) {
|
||||
await processorEventQueue.add({ event, name });
|
||||
const processor = new ProcessorClass();
|
||||
|
||||
if (processor.perform) {
|
||||
Logger.info("worker", `${name} running ${event.name}`, {
|
||||
event,
|
||||
});
|
||||
|
||||
try {
|
||||
await processor.perform(event);
|
||||
} catch (err) {
|
||||
Logger.error(
|
||||
`Error processing ${event.name} in ${name}`,
|
||||
err,
|
||||
event
|
||||
);
|
||||
throw err;
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.error(
|
||||
`Error adding ${event.name} to ${name} queue`,
|
||||
error,
|
||||
event
|
||||
);
|
||||
err = error;
|
||||
}
|
||||
}
|
||||
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
// Jobs for individual processors are processed here. Only applicable events
|
||||
// as unapplicable events were filtered in the global event queue above.
|
||||
processorEventQueue.process(
|
||||
traceFunction({
|
||||
serviceName: "worker",
|
||||
spanName: "process",
|
||||
isRoot: true,
|
||||
})(async function (job) {
|
||||
const { event, name } = job.data;
|
||||
const ProcessorClass = processors[name];
|
||||
|
||||
setResource(`Processor.${name}`);
|
||||
|
||||
if (!ProcessorClass) {
|
||||
throw new Error(
|
||||
`Received event "${event.name}" for processor (${name}) that isn't registered. Check the file name matches the class name.`
|
||||
);
|
||||
}
|
||||
|
||||
const processor = new ProcessorClass();
|
||||
|
||||
if (processor.perform) {
|
||||
Logger.info("worker", `${name} running ${event.name}`, {
|
||||
event,
|
||||
});
|
||||
|
||||
try {
|
||||
await processor.perform(event);
|
||||
} catch (err) {
|
||||
Logger.error(`Error processing ${event.name} in ${name}`, err, event);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
})
|
||||
)
|
||||
.catch((err) => {
|
||||
Logger.fatal("Error starting processorEventQueue", err);
|
||||
});
|
||||
|
||||
// Jobs for async tasks are processed here.
|
||||
taskQueue.process(
|
||||
traceFunction({
|
||||
serviceName: "worker",
|
||||
spanName: "process",
|
||||
isRoot: true,
|
||||
})(async function (job) {
|
||||
const { name, props } = job.data;
|
||||
const TaskClass = tasks[name];
|
||||
taskQueue
|
||||
.process(
|
||||
traceFunction({
|
||||
serviceName: "worker",
|
||||
spanName: "process",
|
||||
isRoot: true,
|
||||
})(async function (job) {
|
||||
const { name, props } = job.data;
|
||||
const TaskClass = tasks[name];
|
||||
|
||||
setResource(`Task.${name}`);
|
||||
setResource(`Task.${name}`);
|
||||
|
||||
if (!TaskClass) {
|
||||
throw new Error(
|
||||
`Task "${name}" is not registered. Check the file name matches the class name.`
|
||||
);
|
||||
}
|
||||
if (!TaskClass) {
|
||||
throw new Error(
|
||||
`Task "${name}" is not registered. Check the file name matches the class name.`
|
||||
);
|
||||
}
|
||||
|
||||
Logger.info("worker", `${name} running`, props);
|
||||
Logger.info("worker", `${name} running`, props);
|
||||
|
||||
const task = new TaskClass();
|
||||
const task = new TaskClass();
|
||||
|
||||
try {
|
||||
await task.perform(props);
|
||||
} catch (err) {
|
||||
Logger.error(`Error processing task in ${name}`, err, props);
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
);
|
||||
try {
|
||||
await task.perform(props);
|
||||
} catch (err) {
|
||||
Logger.error(`Error processing task in ${name}`, err, props);
|
||||
throw err;
|
||||
}
|
||||
})
|
||||
)
|
||||
.catch((err) => {
|
||||
Logger.fatal("Error starting taskQueue", err);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user