Skip to content

Commit f4b6637

Browse files
Merge pull request #6839 from Countly/alerts-newarch-changes
Alerts newarch changes
2 parents 2a66843 + 7bfdbd2 commit f4b6637

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

plugins/alerts/api/ingestor.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const exported = {};
2+
const common = require('../../../api/utils/common.js');
3+
const log = common.log('alerts:ingestor');
4+
const plugins = require('../../pluginManager.js');
5+
const commonLib = require("./parts/common-lib.js");
6+
7+
8+
(function() {
9+
const TRIGGER_BY_EVENT = Object.keys(commonLib.TRIGGERED_BY_EVENT).map(name => ({
10+
module: require("./alertModules/" + name + ".js"),
11+
name
12+
}));
13+
14+
plugins.register("/sdk/process_request", async function(ob) {
15+
const events = ob.params?.qstring?.events;
16+
const app = ob.app;
17+
18+
if (!events || !app) {
19+
return;
20+
}
21+
22+
for (let { module, name } of TRIGGER_BY_EVENT) {
23+
if (name !== "crashes") {
24+
try {
25+
await module.triggerByEvent({ events, app });
26+
}
27+
catch (err) {
28+
log.e("Alert module '" + name + "' couldn't be triggered by event", err);
29+
}
30+
}
31+
}
32+
});
33+
34+
}(exported));
35+
36+
module.exports = exported;

0 commit comments

Comments
 (0)