distribute queue
[Pman.Core] / DataObjects / Core_notify_server.php
index e14ce32..09db236 100644 (file)
@@ -216,13 +216,15 @@ class Pman_Core_DataObjects_Core_notify_server extends DB_DataObject
         $target_len = floor(  ($totalq + $total_add) / $num_servers );
         
         foreach($in_q as $sid => $cq) {
-            if ( $target_len - $cq < 1) {
+            if ( $cq > $target_len) {
                 continue;
             }
             $up[ $sid ] = array_slice($to_add, 0, $target_len - $cq);
         }
-        foreach($to_add as $i) {
-            $up[  $ids[0] ][] = $i;
+        
+        // add the reminder evently
+        foreach($to_add as $n=>$i) {
+            $up[  $ids[$n % $num_servers] ][] = $i;
         }
         
         // distribution needs to go to ones that have the shortest queues. - so to balance out the queues
@@ -283,6 +285,8 @@ class Pman_Core_DataObjects_Core_notify_server extends DB_DataObject
                 $good = $s;
                 break;
             }
+            $offset = ($offset + 1)  % count($servers);
+            var_dump($offset);
         }
         if ($good == false && $allow_same) {
             $good = $this;
@@ -306,12 +310,11 @@ class Pman_Core_DataObjects_Core_notify_server extends DB_DataObject
     {
         // return current server id..
         static $cache = array();
-        var_dump($email);
-        // get the domain..
+         // get the domain..
         $ea = explode('@',$email);
         $dom = strtolower(array_pop($ea));
-        if (isset($cache[$dom])) {
-            return $cache[$dom];
+        if (isset( $cache[$this->id . '-'. $dom])) {
+            return  $cache[$this->id . '-'. $dom];
         }
         
         $cd = DB_DataObject::factory('core_domain')->loadOrCreate($dom);
@@ -320,7 +323,7 @@ class Pman_Core_DataObjects_Core_notify_server extends DB_DataObject
         $bl->server_id = $this->id;
         $bl->domain_id = $cd->id;
         if ($bl->count()) {
-            $cache[$dom] = true;
+            $cache[$this->id . '-'. $dom] = true;
             return true;
         }