forked from cofacts/rumors-line-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
53 lines (44 loc) · 1.42 KB
/
main.js
File metadata and controls
53 lines (44 loc) · 1.42 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
/* eslint no-console: off */
// http://pm2.keymetrics.io/docs/usage/use-pm2-with-cloud-providers/#heroku-google-app-engine-azure
//
const pm2 = require('pm2');
// Set by Heroku or -1 to scale to max cpu core -1
const instances = process.env.WEB_CONCURRENCY || -1;
const maxMemory = process.env.WEB_MEMORY || 512; // " " "
const DEV_CONFIG = {
name: 'heroku-line-bot-local',
script: 'src/index.js',
env: process.env,
watch: true,
interpreter: './node_modules/.bin/babel-node',
};
const PRODUCTION_CONFIG = {
name: 'heroku-line-bot',
script: 'build/index.js',
env: process.env,
exec_mode: 'cluster',
instances,
max_memory_restart: `${maxMemory}M`, // Auto-restart if process takes more than XXmo
};
pm2.connect(() => {
pm2.start(
process.env.NODE_ENV === 'production' ? PRODUCTION_CONFIG : DEV_CONFIG,
err => {
if (err) {
console.error('Error while launching applications', err.stack || err);
return;
}
console.log('PM2 and application has been succesfully started');
// Display logs in standard output
pm2.launchBus((busErr, bus) => {
console.log('[PM2] Log streaming started');
bus.on('log:out', packet => {
console.log('[App:%s] %s', packet.process.name, packet.data);
});
bus.on('log:err', packet => {
console.error('[App:%s][Err] %s', packet.process.name, packet.data);
});
});
}
);
});