status page
[phinde.git] / src / phinde / Queue.php
index a58a257ce7d0c4378c5400b31031e741921e46d2..1033d7ae3e8344c64483929333e143f96b86f4ab 100644 (file)
@@ -9,6 +9,7 @@ class Queue
     {
         $this->gmclient = new \GearmanClient();
         $this->gmclient->addServer('127.0.0.1');
+        $this->queueName = $GLOBALS['phinde']['queuePrefix'] . 'phinde_process';
     }
 
     public function addToProcessList($linkUrl, $actions)
@@ -19,7 +20,7 @@ class Queue
         );
 
         $this->gmclient->doBackground(
-            $GLOBALS['phinde']['queuePrefix'] . 'phinde_process',
+            $this->queueName,
             serialize(
                 array(
                     'url'     => $linkUrl,
@@ -36,5 +37,23 @@ class Queue
             exit(2);
         }
     }
+
+    public function getServerStatus()
+    {
+        $cmd = 'gearadmin --status'
+            . '| grep ' . escapeshellarg($this->queueName);
+        $line = exec($cmd);
+
+        $parts = preg_split('#\s+#', $line);
+        if (count($parts) !== 4) {
+            throw new \Exception('gearadmin status line does not have 4 parts');
+        }
+
+        return array(
+            'tasks'      => $parts[1],
+            'processing' => $parts[2],
+            'workers'    => $parts[3],
+        );
+    }
 }
 ?>