-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (51 loc) · 1.83 KB
/
index.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* ============================================CONFIGURATIONS============================================ */
var commandLineArgs = require('command-line-args');
const argVariables = [
{ name: 'limit', type: Number }, // Max no of command to run
{ name: 'sleep', type: Number }, // sleep between command executions in seconds
{ name: 'file', type: String }, // file containing commands to execute
{ name: 'retry', type: Boolean }, // to retry failed jobs
];
const cli_args = commandLineArgs(argVariables);
if(!cli_args.file)
return console.log('please specify file containing commands to execute');
/* ============================================CONFIGURATIONS============================================ */
var fs = require('fs');
var shell = require('shelljs');
// ----------------------------- Config -----------------------------
var limit = 50;
var sleep = 1;
// --------------------------- Config END ---------------------------
var count = 0;
console.log('retry = '+cli_args.retry);
var config = fs.readFileSync(cli_args.file, 'utf-8');
var lines = config.split(/\r?\n/);
var updated_lines = [];
lines.forEach(line => {
if(count>=limit){
updated_lines.push(line);
return;
}
if(line.indexOf('node run_local')>-1){
var command = line.split('#')[0].trim();
var status = line.split('#')[1].trim();
if(status=='run' || (cli_args.retry && status=='failed')){
// console.log('');
console.log('\n\n\n===============================');
console.log(`>>>>> Line from file: ${command} - ${status}`);
shell.exec(`sleep ${sleep}`);
var a = shell.exec(command);
if(a.stderr)
status='failed';
else
status='done';
updated_lines.push(`${command} # ${status}`);
count++;
}else{
updated_lines.push(line);
}
}else{
updated_lines.push(line);
}
});
fs.writeFileSync(cli_args.file,updated_lines.join('\r\n'));