-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patherror-processing.js
More file actions
61 lines (56 loc) · 1.16 KB
/
error-processing.js
File metadata and controls
61 lines (56 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* Dependencies
*/
const debug = require('debug')('collectify:error-processing');
const highland = require('highland');
const lodash = require('lodash-fp');
const interprocess = require('interprocess-push-stream');
/**
* Application-specific modules
*/
const config = require('./config');
/**
* Create some curryed
* helper functions
* for convenience
* and readability
*/
const wrap = ::highland.wrapCallback;
/**
* Create streams for the channels
* on which we want to
* distribute / emit data.
*
* This uses the push-version
* of the interface, but you
* could also use the pull-version,
* to enable load balancing
* and back-pressure between
* processes
*/
const errorChannel = interprocess.Receiver({
channel: 'errors',
prefix: config.get('database.redis.prefix'),
url: config.get('database.redis.url')
});
/**
* Create a stream
* with the errorChannel
* as the source
*/
const errorMessageStream = highland(createdChannel)
.compact()
.flatten()
.errors((err) => {
console.log(err);
})
/**
* Do stuff with the
* stream of error messages
*
* - mail it to admin
* - log it
*/
errorMessageStream
.fork()
.each(highland.log)