Closed jwulf closed 9 years ago
Also, I added this so SwarmScheduler.js, copied from PhaseMonitor.js:
var redisClient = function(){ return thisAdapter.nativeMiddleware.privateRedisClient; }
And added node-schedule as a dependency to package.json
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.
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...
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?
I would not do that. Create a small swarm and launch it from outside.
[~/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});