Skip to content

Commit

Permalink
Added more log info
Browse files Browse the repository at this point in the history
  • Loading branch information
cadebrown committed Sep 23, 2016
1 parent 8c68f54 commit f0c0506
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 32 deletions.
67 changes: 39 additions & 28 deletions PGS.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const PRIME_FILE = "./primes.dat";

//Create Parser
var parser = new ArgumentParser({
version: '2.0.0',
version: 'v2.0.0',
addHelp: true,
description: 'PGS - Prime Gen Search'
});
Expand Down Expand Up @@ -67,9 +67,42 @@ parser.addArgument(
action: 'storeTrue'
}
);

//We store our parsed args
var args = parser.parseArgs();
var prefs = JSON.parse(fs.readFileSync(args.prefs, 'utf8'));

//Firebase objects
var usr;
var db;
var queue;

//Progress functions
var reject_funcs;


if (args.download > 0) {
initFirebase(function () {
downloadWorkloads(args.download)
});
}

//Callback to run.
var callback = function () {
if (args.download > 0) {
log("Downloaded all. Exiting");
process.exit(0);
} else if (!args.offline) {
initFirebase(runOnline);
} else {
runOffline();
}
}


try {
fs.accessSync(PRIME_FILE);
run();
callback();
} catch (e) {
//Run error
error("Error no prime file! Generating one now.");
Expand All @@ -85,30 +118,8 @@ try {
//When it closes, handle it
pp.on('close', function (code) {
log(`lib Has Finished`);
run();
});
}

//We store our parsed args
var args = parser.parseArgs();
var prefs = JSON.parse(fs.readFileSync(args.prefs, 'utf8'));

//Firebase objects
var usr;
var db;
var queue;

//Progress functions
var reject_funcs;

if (args.download > 0) {
initFirebase(function () {
downloadWorkloads(args.download)
callback();
});
} else if (!args.offline) {
initFirebase(runOnline);
} else {
runOffline();
}

//Main run function
Expand Down Expand Up @@ -142,7 +153,7 @@ function runOffline() {
++i;
currentThreads += 1;
} else {
console.log("This thread finished. " + currentThreads + " threads are still running.");
log("Thread finished. There are " + currentThreads + " threads are still running.");
}
};
ee.on('next', next);
Expand Down Expand Up @@ -311,7 +322,7 @@ function initFirebase(callback) {
};
var app = firebase.initializeApp(config);
firebase.auth().onAuthStateChanged(function (user) {
console.log("Auth changed");
log("Auth changed");
usr = user;
});
db = firebase.database();
Expand All @@ -332,7 +343,7 @@ function log(txt) {
//Logs error info
function error(txt) {
log("error: "+ txt);
fs.appendFileSync('./output/error.txt', txt + "\n", 'utf8');
fs.appendFileSync('./output/error.txt', "\n" + txt + "\n", 'utf8');
}
//Logs a found function
function log_find(txt) {
Expand Down
5 changes: 1 addition & 4 deletions example.prefs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"email": "{{email}}",
"password": "{{password}}",
"threads": 2,
"useclock": false,
"hourStart": 18,
"hourEnd": 4
"threads": 2
}

0 comments on commit f0c0506

Please sign in to comment.