-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathapp.js
43 lines (37 loc) · 866 Bytes
/
app.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
// Import fetch
const fetch = require('node-fetch');
// Import our config
const config = require('./config');
// Get env
const env = process.env;
// Get args
const arg = process.argv.slice(2);
let id = false;
const checkStatus = () => {
if (!id)
return;
fetch(`${config.URL}api/ffmpeg/${id}`).then(res => (res.json())).then((data) => {
if (typeof(data.status) !== 'undefined' && data.status !== false) {
process.exit(parseInt(data.status));
}
}).catch((err) => {
console.error(err);
});
}
// Call the load-balancer
fetch(`${config.URL}api/ffmpeg`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
arg,
env
})
}).then(res => (res.json())).then((data) => {
id = data.id;
setInterval(() => {checkStatus(); }, 10000);
}).catch((err) => {
console.error(err);
});