Permalink
Browse files

Merge pull request #26 from etsy/upstream

Fix for dedicated_only=>true & Fix for priority sorting
  • Loading branch information...
2 parents 81b779d + 42c0912 commit bdd2bb1811dd42fa2f6ef5869340e5db23b8d66d @brianlmoon committed Oct 24, 2011
Showing with 10 additions and 12 deletions.
  1. +10 −12 GearmanManager.php
View
22 GearmanManager.php
@@ -865,18 +865,13 @@ protected function start_worker($worker="all") {
$this->pid = getmypid();
- if($worker == "all"){
-
- $worker_list = array_keys($this->functions);
+ if(count($worker_list) > 1){
// shuffle the list to avoid queue preference
shuffle($worker_list);
// sort the shuffled array by priority
uasort($worker_list, array($this, "sort_priority"));
-
- } else {
- $worker_list = array($worker);
}
$this->start_lib_worker($worker_list);
@@ -907,16 +902,19 @@ protected function start_worker($worker="all") {
* Sorts the function list by priority
*/
private function sort_priority($a, $b) {
- if(!isset($a["priority"])){
- $a["priority"] = 0;
+ $func_a = $this->functions[$a];
+ $func_b = $this->functions[$b];
+
+ if(!isset($func_a["priority"])){
+ $func_a["priority"] = 0;
}
- if(!isset($b["priority"])){
- $b["priority"] = 0;
+ if(!isset($func_b["priority"])){
+ $func_b["priority"] = 0;
}
- if ($a["priority"] == $b["priority"]) {
+ if ($func_a["priority"] == $func_b["priority"]) {
return 0;
}
- return ($a["priority"] > $b["priority"]) ? -1 : 1;
+ return ($func_a["priority"] > $func_b["priority"]) ? -1 : 1;
}
/**

0 comments on commit bdd2bb1

Please sign in to comment.