-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.js
44 lines (31 loc) · 995 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
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
/**
* @name worker
* @description job worker process for open311 API
*
* Alert!: Please ensure your have installed Redis Server
*
* Alert!: Run worker in the separate process from main process
*
* Recommendation!: It also adviced to run each worker per process or per machine
* with any number of concurrency(10 is sufficient max worker so far)
*/
/* dependencies */
const path = require('path');
const env = require('@lykmapipo/env');
const { worker, httpServer } = require('@lykmapipo/postman');
const mkdir = require('mkdir-p');
const { getNumber } = env;
/* constants */
const QUEUE_HTTP_PORT = getNumber('QUEUE_HTTP_PORT');
//build logs directory if does not exists
const logPath = path.join(__dirname, 'logs');
mkdir.sync(logPath);
/* setup models */
require(path.join(__dirname, 'app', 'initializers', 'mongoose'));
/* run work */
worker.start();
/* open web interface to monitor jobs */
if (QUEUE_HTTP_PORT) {
httpServer.listen(QUEUE_HTTP_PORT);
}