This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/server/events.js
Tom Moor 44cb509ebf
Post to Slack (#603)
* Migrations

* WIP: Integration model, slack perms / hooks

* So so rough it pains me. Building this new model is revealing just how much needs to be refactored

* Working connect and post

* Cleanup UI, upating documents

* Show when slack command is connected

* stash

* 💚

* Add documents.update trigger

* Authorization, tidying

* Fixed integration policy

* pick integration presenter keys
2018-04-03 20:36:25 -07:00

44 lines
1.1 KiB
JavaScript

// @flow
import Queue from 'bull';
import debug from 'debug';
import services from './services';
import { Collection, Document } from './models';
type DocumentEvent = {
name: 'documents.create' | 'documents.update' | 'documents.publish',
model: Document,
};
type CollectionEvent = {
name: 'collections.create' | 'collections.update',
model: Collection,
};
export type Event = DocumentEvent | CollectionEvent;
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 function(job) {
const names = Object.keys(services);
names.forEach(name => {
const service = services[name];
if (service.on) {
serviceEventsQueue.add({ service: name, ...job.data });
}
});
});
// this queue processes an individual event for a specific service
serviceEventsQueue.process(async function(job) {
const event = job.data;
const service = services[event.service];
if (service.on) {
service.on(event);
}
});
export default globalEventsQueue;