Skip to content

Commit

Permalink
scope passing ok for tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
evantahler committed Feb 14, 2012
1 parent edd547f commit 4185cf9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 44 deletions.
59 changes: 34 additions & 25 deletions initializers/initTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,45 @@ var initTasks = function(api, next)

api.tasks.process = function(api){
clearTimeout(api.tasks.processTimer);
api.tasks.startPeriodicTasks(api, function(){
if(api.tasks.queue.length > 0){
var thisTask = api.tasks.queue[0];
api.tasks.queue = api.tasks.queue.splice(1);
if(api.actionCluster.connectionsToPeers.length < 2){
api.tasks.run(api, thisTask.taskName, thisTask.params, function(){
api.tasks.processTimer = setTimeout(api.tasks.process, api.tasks.cycleTimeMS, api);
});
}else{
api.actionCluster.cache.load(api, "_periodicTasks", function(clusterResp){
var otherPeerTasks = {}
for(var i in clusterResp){
for(var j in clusterResp[i]['value']){
otherPeerTasks[clusterResp[i]['value'][j]] = true;
}
if(api.tasks.queue.length > 0){
var thisTask = api.tasks.queue[0];
api.tasks.queue = api.tasks.queue.splice(1);
if(api.actionCluster.connectionsToPeers.length < 2){
api.tasks.run(api, thisTask.taskName, thisTask.params, function(){
api.tasks.processTimer = setTimeout(api.tasks.process, api.tasks.cycleTimeMS, api);
});
}else{
api.actionCluster.cache.load(api, "_periodicTasks", function(clusterResp){
var otherPeerTasks = {}
for(var i in clusterResp){
for(var j in clusterResp[i]['value']){
otherPeerTasks[clusterResp[i]['value'][j]] = true;
}
var t = api.tasks.tasks[thisTask.taskName];
}
var t = api.tasks.tasks[thisTask.taskName];
api.cache.load(api, "_periodicTasks", function(_periodicTasks){
if(t.scope == "all" || otherPeerTasks[thisTask.taskName] != true){
api.tasks.run(api, thisTask.taskName, thisTask.params, function(){
api.tasks.processTimer = setTimeout(api.tasks.process, api.tasks.cycleTimeMS, api);
if(_periodicTasks.indexOf(t.name) < 0){
_periodicTasks.push(t.name);
}
api.cache.save(api, "_periodicTasks", _periodicTasks, null, function(resp){
api.tasks.processTimer = setTimeout(api.tasks.process, api.tasks.cycleTimeMS, api);
});
});
}else{
api.tasks.processTimer = setTimeout(api.tasks.process, api.tasks.cycleTimeMS, api);
_periodicTasks.splice(_periodicTasks.indexOf(t.name),1);
api.cache.save(api, "_periodicTasks", _periodicTasks, null, function(resp){
api.tasks.timers[t.name] = setTimeout(api.tasks.enqueue, t.frequency, api, t.name);
api.tasks.processTimer = setTimeout(api.tasks.process, api.tasks.cycleTimeMS, api);
});
}
});
}
}else{
api.tasks.processTimer = setTimeout(api.tasks.process, api.tasks.cycleTimeMS, api);
});
}
});
}else{
api.tasks.processTimer = setTimeout(api.tasks.process, api.tasks.cycleTimeMS, api);
}
};

api.tasks.startPeriodicTasks = function(api, next){
Expand Down Expand Up @@ -123,10 +132,10 @@ var initTasks = function(api, next)
}
}

api.cache.save(api, "_periodicTasks", [], null, function(){
api.tasks.startPeriodicTasks(api, function(){
api.tasks.process(api);
next();
});
next();
})
}

/////////////////////////////////////////////////////////////////////
Expand Down
19 changes: 0 additions & 19 deletions tasks/runOne.js

This file was deleted.

0 comments on commit 4185cf9

Please sign in to comment.