Skip to content

Commit

Permalink
fancy logging
Browse files Browse the repository at this point in the history
  • Loading branch information
pan261 committed Nov 18, 2021
1 parent 757236b commit 233faed
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
38 changes: 28 additions & 10 deletions taskRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ var initInterval = null;
var updateInterval = null;

const fetchToken = () => {
console.log(
"\x1b[34mtaskRunner.js::fetchToken:",
"\x1b[0mAttempting to fetch token");
axios({
method: 'GET',
url: 'http://localhost:3000/credentials'
Expand All @@ -23,28 +26,43 @@ const fetchToken = () => {
if (Object.keys(res.data).length == 5) {
credentials = res.data;
clearInterval(initInterval);
console.log("credentials received");
console.log(
"\x1b[32mtaskRunner.js::fetchToken:",
"\x1b[0mCredentials received");
} else {
console.log(
"\x1b[34mtaskRunner.js::fetchToken:",
"\x1b[0mAuthenticate through localhost:3000/auth")
}
})
.catch(err => {
console.log(err);
console.log(
"\x1b[31mtaskRunner.js::fetchToken:",
"\x1b[0mError accessing localhost:3000/credentials"
);
});
}

fetchToken();
initInterval = setInterval(() => {
const getCredentials = () => {
fetchToken();
console.log("waiting for initial auth")
}, 10000);
updateInterval = setInterval(fetchToken, 3300 * 1000);

initInterval = setInterval(() => {
fetchToken();
console.log(
"\x1b[33mtaskRunner.js::getCredentials:",
"\x1b[0mWaiting for initial auth")
}, 10000);
updateInterval = setInterval(fetchToken, 3300 * 1000);
}

const dispatchWatcher = () => {
if (credentials == null) {
console.log("no credentials");
console.log(
"\x1b[33mtaskRunner.js::dispatchWatcher:",
"\x1b[0mNo credentials");
} else {
watcher.watch(projectID, 'urn:adsk.wipprod:fs.folder:co.ltuYad4ZTtieJLm6j3MGuA', credentials, 5);
}
}

setInterval(dispatchWatcher, 5000)
getCredentials();
setInterval(dispatchWatcher, 5000);
6 changes: 4 additions & 2 deletions watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ exports.watch = (projectID, folderID, credentials, interval) => {
})
.then(data => {
if (data === undefined) { // no new files changed, return
console.log("no new files modified since " + dateXSecondsAgo.toISOString());
console.log(
"\x1b[34mwatcher.js::watch:",
"\x1b[0mNo new files modified since " + dateXSecondsAgo.toISOString());
return;
}

for (var index in data) {
// console.log(data[index]);
var displayName = data[index].attributes.displayName;
var lastModifiedTime = data[index].attributes.lastModifiedTime;
console.log(displayName + " was modified at " + lastModifiedTime);
console.log("\x1b[34mwatcher.js::watch: \x1b[0m" + displayName + " was modified at " + lastModifiedTime);

// TODO: if item is not in db, add to db and then download

Expand Down

0 comments on commit 233faed

Please sign in to comment.