Files
outline/server/queues/processors/DebounceProcessor.ts
Tom Moor 91d8d27f2d feat: Render diffs in email notifications (#4164)
* deps

* diffCompact

* Diffs in email

* test

* fix: Fade deleted images
fix: Don't include empty paragraphs as context
fix: Allow for same image multiple times and refactor

* Remove target _blank

* fix: Table heading incorrect color
2022-09-24 14:29:11 -07:00

52 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import env from "@server/env";
import Document from "@server/models/Document";
import { Event } from "@server/types";
import { globalEventQueue } from "..";
import BaseProcessor from "./BaseProcessor";
export default class DebounceProcessor extends BaseProcessor {
static applicableEvents: Event["name"][] = [
"documents.update",
"documents.update.delayed",
];
async perform(event: Event) {
switch (event.name) {
case "documents.update": {
globalEventQueue.add(
{ ...event, name: "documents.update.delayed" },
{
// speed up revision creation in development, we don't have all the
// time in the world.
delay: (env.ENVIRONMENT === "development" ? 0.5 : 5) * 60 * 1000,
}
);
break;
}
case "documents.update.delayed": {
const document = await Document.findByPk(event.documentId, {
attributes: ["updatedAt"],
});
// If the document has been deleted then prevent further processing
if (!document) {
return;
}
// If the document has been updated since we initially queued the delayed
// event then abort, there must be another updated event in the queue
// this functions as a simple distributed debounce.
if (document.updatedAt > new Date(event.createdAt)) {
return;
}
globalEventQueue.add({ ...event, name: "documents.update.debounced" });
break;
}
default:
}
}
}