* Big upgrades * WIP: Stash * Stash, 30 flow errors left * Downgrade mobx * WIP * When I understand the difference between class and instance methods * 💚 * Fixes: File import Model saving edge cases pinning and starring docs Collection editing Upgrade mobx devtools * Notification settings saving works * Disabled settings * Document mailer * Working notifications * Colletion created notification Ensure not notified for own actions * Tidy up * Document updated event only for document creation Add indexes Notification setting on user creation * Commentary * Fixed: Notification setting on signup * Fix document move / duplicate stale data Add BaseModel.refresh method * Fixes: Title in sidebar not updated after editing document * 💚 * Improve / restore error handling Better handle offline errors * 👕
51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
// @flow
|
|
import Queue from 'bull';
|
|
import services from './services';
|
|
import { Collection, Document, Integration } from './models';
|
|
|
|
type DocumentEvent = {
|
|
name: 'documents.create' | 'documents.update' | 'documents.publish',
|
|
model: Document,
|
|
};
|
|
|
|
type CollectionEvent = {
|
|
name: 'collections.create' | 'collections.update',
|
|
model: Collection,
|
|
};
|
|
|
|
type IntegrationEvent = {
|
|
name: 'integrations.create' | 'integrations.update',
|
|
model: Integration,
|
|
};
|
|
|
|
export type Event = DocumentEvent | CollectionEvent | IntegrationEvent;
|
|
|
|
const globalEventsQueue = new Queue('global events', process.env.REDIS_URL);
|
|
const serviceEventsQueue = new Queue('service events', process.env.REDIS_URL);
|
|
|
|
// this queue processes global events and hands them off to service hooks
|
|
globalEventsQueue.process(async job => {
|
|
const names = Object.keys(services);
|
|
names.forEach(name => {
|
|
const service = services[name];
|
|
if (service.on) {
|
|
serviceEventsQueue.add(
|
|
{ service: name, ...job.data },
|
|
{ removeOnComplete: true }
|
|
);
|
|
}
|
|
});
|
|
});
|
|
|
|
// this queue processes an individual event for a specific service
|
|
serviceEventsQueue.process(async job => {
|
|
const event = job.data;
|
|
const service = services[event.service];
|
|
|
|
if (service.on) {
|
|
service.on(event);
|
|
}
|
|
});
|
|
|
|
export default globalEventsQueue;
|