chore: Bringing across edits from enterprise codebase

This commit is contained in:
Tom Moor
2022-04-16 19:46:01 -07:00
parent 0b5e48621a
commit b1aba32b62
7 changed files with 13 additions and 11 deletions

View File

@@ -1,4 +1,5 @@
import chalk from "chalk";
import { isEmpty } from "lodash";
import winston from "winston";
import env from "@server/env";
import Metrics from "@server/logging/metrics";
@@ -32,10 +33,10 @@ class Logger {
: winston.format.combine(
winston.format.colorize(),
winston.format.printf(
({ message, level, label }) =>
({ message, level, label, ...extra }) =>
`${level}: ${
label ? chalk.bold("[" + label + "] ") : ""
}${message}`
}${message} ${isEmpty(extra) ? "" : JSON.stringify(extra)}`
)
),
})

View File

@@ -1,7 +1,7 @@
import { Event } from "@server/types";
export default abstract class BaseProcessor {
static applicableEvents: Event["name"][] = [];
static applicableEvents: (Event["name"] | "*")[] = [];
public abstract perform(event: Event): Promise<void>;
}

View File

@@ -294,7 +294,7 @@ export default class WebsocketsProcessor {
}
case "collections.add_group": {
const group = await Group.findByPk(event.data.groupId);
const group = await Group.findByPk(event.modelId);
if (!group) {
return;
}
@@ -320,7 +320,7 @@ export default class WebsocketsProcessor {
}
case "collections.remove_group": {
const group = await Group.findByPk(event.data.groupId);
const group = await Group.findByPk(event.modelId);
if (!group) {
return;
}

View File

@@ -2,14 +2,12 @@ import { subDays } from "date-fns";
import { Op } from "sequelize";
import { sequelize } from "@server/database/sequelize";
import InviteReminderEmail from "@server/emails/templates/InviteReminderEmail";
import { APM } from "@server/logging/tracing";
import { User } from "@server/models";
import { UserFlag } from "@server/models/User";
import BaseTask, { TaskPriority } from "./BaseTask";
type Props = undefined;
@APM.trace()
export default class InviteReminderTask extends BaseTask<Props> {
public async perform() {
const users = await User.scope("invited").findAll({

View File

@@ -194,9 +194,9 @@ router.post("collections.add_group", auth(), async (ctx) => {
collectionId: collection.id,
teamId: collection.teamId,
actorId: ctx.state.user.id,
modelId: groupId,
data: {
name: group.name,
groupId,
},
ip: ctx.request.ip,
});
@@ -229,9 +229,9 @@ router.post("collections.remove_group", auth(), async (ctx) => {
collectionId: collection.id,
teamId: collection.teamId,
actorId: ctx.state.user.id,
modelId: groupId,
data: {
name: group.name,
groupId,
},
ip: ctx.request.ip,
});

View File

@@ -46,7 +46,10 @@ export default function init() {
// 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)) {
} else if (
ProcessorClass.applicableEvents.includes(event.name) ||
ProcessorClass.applicableEvents.includes("*")
) {
await processorEventQueue.add({ event, name });
}
} catch (error) {

View File

@@ -174,9 +174,9 @@ export type CollectionEvent =
collectionId: string;
teamId: string;
actorId: string;
modelId: string;
data: {
name: string;
groupId: string;
};
ip: string;
}