-
Notifications
You must be signed in to change notification settings - Fork 49
/
worker.js
32 lines (25 loc) · 678 Bytes
/
worker.js
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
var http = require('http');
var logger = require('logfmt');
var throng = require('throng');
var config = require('./config');
var app = require('./app');
http.globalAgent.maxSockets = Infinity;
throng(start, { workers: config.worker_concurrency });
function start() {
logger.log({
type: 'info',
msg: 'starting worker',
concurrency: config.concurrency
});
var instance = app(config);
instance.on('ready', beginWork);
process.on('SIGTERM', shutdown);
function beginWork() {
instance.on('lost', shutdown);
instance.startScraping();
}
function shutdown() {
logger.log({ type: 'info', msg: 'shutting down' });
process.exit();
}
}