diff --git a/PGS.js b/PGS.js index 8a00da8..0b83a88 100644 --- a/PGS.js +++ b/PGS.js @@ -80,14 +80,6 @@ var queue; //Progress functions var reject_funcs; -error("Started running at " + new Date().toString()); - -if (args.download > 0) { - initFirebase(function () { - downloadWorkloads(args.download) - }); -} - //Callback to run. var callback = function () { if (args.download > 0) { @@ -100,24 +92,35 @@ var callback = function () { } } +var start_run = function() { + try { + fs.accessSync(PRIME_FILE); + callback(); + } catch (e) { + //Run error + error("Error no prime file! Generating one now."); + error(JSON.stringify(e)); + //Spawn + const pp = spawn("./lib.o", [PRIME_FILE]); + //When it closes, handle it + pp.on('close', function (code) { + log(`lib Has finished generating primes.dat`); + callback(); + }); + } +} -try { - fs.accessSync(PRIME_FILE); - callback(); -} catch (e) { - //Run error - error("Error no prime file! Generating one now."); - error(JSON.stringify(e)); - //Spawn - const pp = spawn("./lib.o", [PRIME_FILE]); +error("Started running at " + new Date().toString()); - //When it closes, handle it - pp.on('close', function (code) { - log(`lib Has finished generating primes.dat`); - callback(); +if (args.download > 0) { + initFirebase(function () { + downloadWorkloads(args.download); }); +} else { + start_run(); } + //Main run function function runOffline() { log("Running offline using " + prefs.threads + " threads"); @@ -247,7 +250,7 @@ function downloadWorkloads(n) { fs.writeFileSync("./workloads/" + getWorkloadIdentifier(data) + ".workload", JSON.stringify(data), 'utf8'); resolve(); if (workloadsDownloaded >= n) { - log("Downloaded workloads"); + log("Downloaded all workloads"); shutdown(); } }); @@ -372,4 +375,7 @@ function shutdown() { process.on('SIGINT', function() { error("SIGINT sent"); shutdown(); -}); \ No newline at end of file +}); + +//Keep alive +setInterval(function(){}, Number.POSITIVE_INFINITY); \ No newline at end of file