-
Notifications
You must be signed in to change notification settings - Fork 6
/
bl-app-wait.js
executable file
·32 lines (28 loc) · 1.07 KB
/
bl-app-wait.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
#!/usr/bin/env node
const config = require('./config');
const commander = require('commander');
const util = require('./util');
const request = require('request-promise-native');
commander
.usage('[options] <task_id>')
.option('-i, --id <task_id>', 'id of task to wait for')
.parse(process.argv);
try {
if(commander.args.length > 0) commander.id = commander.id || commander.args[0];
if(!commander.id) throw new Error("please specify task id");
} catch(err) {
console.error(err.toString());
process.exit(1);
}
util.loadJwt().then(jwt => {
let headers = { "Authorization": "Bearer " + jwt };
request.get({ url: config.api.amaretti+"/task?find=" + JSON.stringify({_id: commander.id}), headers, json: true}).then(body=>{
if (body.tasks.length == 0) throw new Error("no tasks found with id " + commander.id);
util.waitForFinish(headers, body.tasks[0], process.stdout.isTTY, async err => {
if (err) throw err;
console.log("(done waiting)");
});
}).catch(err=>{
console.error(err.message);
});
});