diff --git a/routes/worker_collection.js b/routes/worker_collection.js index e82e309..3542745 100644 --- a/routes/worker_collection.js +++ b/routes/worker_collection.js @@ -9,7 +9,23 @@ var settings = require('./workers.json'); var Runner = (function(){ var proto = {}; var __empty = function(){}; + + proto.runnerMap = {}; + + proto.cleanUp = function(label){ + delete proto.runnerMap[label]; + }; + proto.set = function(runner){ + proto.runnerMap[runner.label] = runner; + proto.runnerMap[runner.label] = runner; + }; + + proto.get = function(label){ + return proto.runnerMap[label]; + }; + + proto.create = function(config){ var runner = Object.create(proto); Object.assign(runner, config); @@ -189,27 +205,16 @@ var WorkerCollection = (function(){ // about 3 minutes to create a worker. workers.currentCreating = 0; - //************************************************** - //************************************************** - // TODO: Move to Runners - workers.runnerMap = {}; - - workers.__runnerCleanUp = function(label){ - delete workers.runnerMap[label]; - }; + // REMOVE THIS + worker.runnerMap = Runner.runnerMap; workers.setRunner = function(runner){ - workers.runnerMap[runner.label] = runner; - var __empty = runner.cleanUp; - runner.cleanUp = function(){ - workers.__runnerCleanUp(runner.label); - runner.cleanUp = __empty; - }; + Runner.set(runner); }; workers.getRunner = function(label){ - return workers.runnerMap[label]; + return Runner.get(label); }; //************************************************** @@ -316,6 +321,7 @@ var WorkerCollection = (function(){ // TODO: move to seperate method doapi.dropletsByTag(tag, function(data){ data = JSON.parse(data); + console.log(data); console.log(`Deleting ${data['droplets'].length} workers tagged ${tag}. Workers`, data['droplets'].map(function(item){ return item.name+' | '+item.id; diff --git a/testAPI.js b/testAPI.js index 0910155..9366630 100644 --- a/testAPI.js +++ b/testAPI.js @@ -45,7 +45,12 @@ sleep(${sleepTime}) body = JSON.parse(body); res = (Buffer.from(body.res, 'base64').toString('ascii')); } - console.log(`${id} with results ${res}. Errors ${errors}. No runner ${noRunner}. Completed ${completed}`); + console.log(` + ${id} with results ${res}. + Errors ${errors}. + No runner ${noRunner}. + Completed ${completed} + `); callback()