decentralized-internet
Version:
An NPM library of programs to create decentralized web and distributed computing projects
1 lines • 3.68 kB
JavaScript
var clusterpost=require("clusterpost-lib"),path=require("path"),Promise=require("bluebird"),argv=require("minimist")(process.argv.slice(2));const os=require("os"),fs=require("fs");var agentoptions={rejectUnauthorized:!1};clusterpost.setAgentOptions(agentoptions);const help=function(){console.error("Help: Download tasks from the server."),console.error("\nOptional parameters:"),console.error("--dir Output directory, default: ./out"),console.error("--status one of [DONE, RUN, FAIL, EXIT, UPLOADING, CREATE], default: DONE"),console.error("--print , if provided the information is printed only"),console.error("--delete, default false, when downloading jobs with status 'DONE', the jobs will be deleted upon completion"),console.error("--j job id, default: "),console.error("--executable executable, default: all executables"),console.error("--email email, default: (authenticated user)"),console.error("--config_codename codename, default: clusterpost")};(argv.h||argv.help)&&(console.error("Help: Download tasks from the server."),console.error("\nOptional parameters:"),console.error("--dir Output directory, default: ./out"),console.error("--status one of [DONE, RUN, FAIL, EXIT, UPLOADING, CREATE], default: DONE"),console.error("--print , if provided the information is printed only"),console.error("--delete, default false, when downloading jobs with status 'DONE', the jobs will be deleted upon completion"),console.error("--j job id, default: "),console.error("--executable executable, default: all executables"),console.error("--email email, default: (authenticated user)"),console.error("--config_codename codename, default: clusterpost"),process.exit(1));var deletejobs=!1;void 0!==argv.delete&&(console.log("After successful download, jobs with status DONE will be deleted!"),deletejobs=!0);var userEmail=void 0;argv.email&&(userEmail=argv.email);var outputdir="./out";argv.dir&&(outputdir=argv.dir);var status="DONE";argv.status&&(status=argv.status);var jobid=argv.j,executable=argv.executable,print=argv.print;console.log("Output dir",outputdir),console.log("Status",status),jobid&&console.log("jobid",jobid),executable&&console.log("executable",executable),print&&console.log("print",print);var config_codename="clusterpost";argv.config_codename&&(config_codename=argv.config_codename),clusterpost.start(path.join(os.homedir(),"."+config_codename+".json")).then(function(){return print?jobid?clusterpost.getDocument(jobid).then(function(e){console.log(JSON.stringify(e,null,2))}):clusterpost.getJobs(executable,status,userEmail).then(function(e){console.log(JSON.stringify(e,null,2))}):jobid?clusterpost.getDocument(jobid).then(function(e){if(e.outputdir)return clusterpost.getJobOutputs(e,e.outputdir);var o=void 0;return o=e.name?path.join(outputdir,e.name):path.join(outputdir,e._id),clusterpost.getJobOutputs(e,o)}).then(function(){if(console.log("job downloaded..."),deletejobs)return console.log("Deleting job"),clusterpost.deleteJob(jobid)}):clusterpost.getJobs(executable,status,userEmail).then(function(e){return Promise.map(e,function(e){if(console.log(JSON.stringify(e,null,2)),e.outputdir)return clusterpost.getJobOutputs(e,e.outputdir).then(function(){if(e.name?console.log(e.name,"downloaded..."):console.log(e._id,"downloaded..."),deletejobs)return console.log("Deleting job"),clusterpost.deleteJob(e._id)});var o=void 0;return o=e.name?path.join(outputdir,e.name):path.join(outputdir,e._id),clusterpost.getJobOutputs(e,o).then(function(){if(e.name?console.log(e.name,"downloaded..."):console.log(e._id,"downloaded..."),deletejobs)return console.log("Deleting job"),clusterpost.deleteJob(e._id)})},{concurrency:1})})}).catch(console.error);