From 757236bc71945a158865ba36e0b809a8165a4b6c Mon Sep 17 00:00:00 2001 From: pan261 Date: Thu, 18 Nov 2021 16:00:18 -0500 Subject: [PATCH] task runner inital setup --- manager.js | 19 ------------------- taskRunner.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 19 deletions(-) delete mode 100644 manager.js create mode 100644 taskRunner.js diff --git a/manager.js b/manager.js deleted file mode 100644 index 4a5c1ff..0000000 --- a/manager.js +++ /dev/null @@ -1,19 +0,0 @@ -const axios = require('axios'); -const watcher = require('./watcher'); -require('dotenv').config(); - -/** - * This file will be responsible for managing the watcher - * as well as ensuring the credentials are avaiable - * */ - -axios({ - method: 'GET', - url: 'http://localhost:3000/credentials' -}).then(res => { - console.log(res.data); -}); - -const projectID = "a.YnVzaW5lc3M6cHVyZHVlMjY5NiMyMDIxMTEwODQ2NDQzMzk3Ng"; -console.log(process.env.CREDENTIALS); -// setInterval(() => watcher.watch(projectID, 'urn:adsk.wipprod:fs.folder:co.ltuYad4ZTtieJLm6j3MGuA', ), 5000) \ No newline at end of file diff --git a/taskRunner.js b/taskRunner.js new file mode 100644 index 0000000..44b5df9 --- /dev/null +++ b/taskRunner.js @@ -0,0 +1,50 @@ +const axios = require('axios'); +const watcher = require('./watcher'); +require('dotenv').config(); + +/** + * This file will be responsible for managing the watcher + * as well as ensuring the credentials are avaiable + * */ + +const projectID = "a.YnVzaW5lc3M6cHVyZHVlMjY5NiMyMDIxMTEwODQ2NDQzMzk3Ng"; + +var credentials = null; +var initInterval = null; +var updateInterval = null; + +const fetchToken = () => { + axios({ + method: 'GET', + url: 'http://localhost:3000/credentials' + }) + .then(res => { + // console.log(res.data); + if (Object.keys(res.data).length == 5) { + credentials = res.data; + clearInterval(initInterval); + console.log("credentials received"); + } + }) + .catch(err => { + console.log(err); + }); +} + +fetchToken(); +initInterval = setInterval(() => { + fetchToken(); + console.log("waiting for initial auth") +}, 10000); +updateInterval = setInterval(fetchToken, 3300 * 1000); + + +const dispatchWatcher = () => { + if (credentials == null) { + console.log("no credentials"); + } else { + watcher.watch(projectID, 'urn:adsk.wipprod:fs.folder:co.ltuYad4ZTtieJLm6j3MGuA', credentials, 5); + } +} + +setInterval(dispatchWatcher, 5000) \ No newline at end of file