PrivateSky / swarmcore

Swarm 2.0 implementation
Other
15 stars 4 forks source link

SwarmScheduler loads rules before redis pubsub completes #3

Closed jwulf closed 9 years ago

jwulf commented 9 years ago

[~/workspace/SwarmCore] $ cd '/Users/sitapati/workspace/SwarmCore'; 'node' --debug-brk=52963 'etc/adapters/SwarmScheduler.js' Debugger listening on port 52963 Loading /Users/sitapati/workspace/SwarmCore/autolib//SwarmAcl.js TypeError: Cannot read property 'hgetall' of undefined at loadRules (/Users/sitapati/workspace/SwarmCore/etc/adapters/SwarmScheduler.js:19:30) at Object. (/Users/sitapati/workspace/SwarmCore/etc/adapters/SwarmScheduler.js:109:1) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Module.runMain as _onTimeout at Timer.listOnTimeout (timers.js:110:15)

Following the trace, loadRules() is called in SwarmScheduler.js before redisComImpl.pubsubRedisClient.on("ready", function is executed.

It looks like loadRules() should be called in something like onCmdRedisReady(error). Is there a way to hook a callback to this?

Maybe you could pass an onReady function to the createAdapter constructor?

So it would be something like:

SwarmScheduler.js

var thisAdapter;

adapterReady = function (err) { if (!err) {loadRules();} };

thisAdapter = core.createAdapter("SwarmScheduler", {onReady: adapterReady});

jwulf commented 9 years ago

Also, I added this so SwarmScheduler.js, copied from PhaseMonitor.js:

var redisClient = function(){ return thisAdapter.nativeMiddleware.privateRedisClient; }

jwulf commented 9 years ago

And added node-schedule as a dependency to package.json

jwulf commented 9 years ago

Adding it to the existing onReady function doesn't work.

var thisAdapter = core.createAdapter("SwarmScheduler"); thisAdapter.onReady(loadRules);

Node _SwarmScheduler(2f1c1911-fe80-486c-94d8-3c66f728fa7e) ready for swarms! Loading Rules Use createSwarmCallback only in phase code context. Use of createSwarmCallback or .swait in upper callbacks Debug error: [Error: Invalid context! Call this function in a swarm phase only!] Error: Invalid context! Call this function in a swarm phase only! at createSwarmCallback (/Users/sitapati/workspace/SwarmCore/lib/SwarmCore.js:156:15) at Function. (/Users/sitapati/workspace/SwarmCore/node_modules/asynchron/lib/asynchron.js:91:23) at loadRules (/Users/sitapati/workspace/SwarmCore/etc/adapters/SwarmScheduler.js:27:8) at /Users/sitapati/workspace/SwarmCore/com/redisComImpl.js:827:13 at Array.forEach (native) at callWaitingForReady (/Users/sitapati/workspace/SwarmCore/com/redisComImpl.js:826:22) at /Users/sitapati/workspace/SwarmCore/com/redisComImpl.js:791:13 at callItFinally (/Users/sitapati/workspace/SwarmCore/node_modules/asynchron/lib/asynchron.js:102:26) at _endCall (/Users/sitapati/workspace/SwarmCore/node_modules/asynchron/lib/asynchron.js:84:17) at /Users/sitapati/workspace/SwarmCore/node_modules/asynchron/lib/asynchron.js:117:25 Error at errorLogger (/Users/sitapati/workspace/SwarmCore/node_modules/asynchron/lib/asynchron.js:40:57) at callItFinally (/Users/sitapati/workspace/SwarmCore/node_modules/asynchron/lib/asynchron.js:107:21) at _endCall (/Users/sitapati/workspace/SwarmCore/node_modules/asynchron/lib/asynchron.js:84:17) at /Users/sitapati/workspace/SwarmCore/node_modules/asynchron/lib/asynchron.js:117:25 at _fulfilled (/Users/sitapati/workspace/SwarmCore/node_modules/q/q.js:794:54) at self.promiseDispatch.done (/Users/sitapati/workspace/SwarmCore/node_modules/q/q.js:823:30) at Promise.promise.promiseDispatch (/Users/sitapati/workspace/SwarmCore/node_modules/q/q.js:756:13) at /Users/sitapati/workspace/SwarmCore/node_modules/q/q.js:564:44 at flush (/Users/sitapati/workspace/SwarmCore/node_modules/q/q.js:110:17) at process._tickCallback (node.js:355:11)

salboaie commented 9 years ago

I''m working to add better dependency injection concepts in SwarmCore so for now I will not do anything here. Check semantic-firewall module (especialy test with container) for an impression about how it will be next. For now I never really used SwarmScheduler for real so remained a ghost implementation until I will get time to clean things there...

jwulf commented 9 years ago

OK, I will hardcode my scheduler in an adapter, or using timeouts in swarms in the meantime :)

I guess if I need a task to run every day, I can just put a timeout in the last phase of a swarm and have it move back to the first phase when the timeout completes - although, would that cause a memory leak?

salboaie commented 9 years ago

I would not do that. Create a small swarm and launch it from outside.