Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Rework data upload and some util functions #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions bl-app-wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,25 @@ 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);
}
let program = new commander.Command();
program
.storeOptionsAsProperties(true)
.argument('task-id', 'Id of the task to wait for')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep -id --id options to make it backward compatible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok!

.parse();

program.parse();

let taskId = program.args[0];

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)");
request.get({ url: config.api.amaretti+"/task?find=" + JSON.stringify({_id: taskId}), headers, json: true})
.then(async (body) => {
if (body.tasks.length == 0) throw new Error("No tasks found with Id " + taskId);
await util.waitForFinish(headers, body.tasks[0], process.stdout.isTTY);
console.error("(done waiting)");
}).catch(err => {
console.error(err.message);
});
}).catch(err=>{
console.error(err.message);
});
});
7 changes: 1 addition & 6 deletions bl-bids-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,7 @@ util.loadJwt().then(async jwt => {
}}).then(body=>{
let task = body.task;
console.log("Waiting for upload task to be ready...");
return new Promise((resolve, reject)=>{
util.waitForFinish(headers, task, true, err=>{
if(err) return reject(err);
resolve(task);
});
});
return util.waitForFinish(headers, task, true);
});
}

Expand Down
Loading