status page
[phinde.git] / src / phinde / Queue.php
index 98f6462cd90ccc7163c60605dbae106c2b17de18..1033d7ae3e8344c64483929333e143f96b86f4ab 100644 (file)
@@ -9,46 +9,51 @@ class Queue
     {
         $this->gmclient = new \GearmanClient();
         $this->gmclient->addServer('127.0.0.1');
     {
         $this->gmclient = new \GearmanClient();
         $this->gmclient->addServer('127.0.0.1');
+        $this->queueName = $GLOBALS['phinde']['queuePrefix'] . 'phinde_process';
     }
 
     }
 
-    public function addToIndex($linkUrl, $linkTitle, $sourceUrl)
+    public function addToProcessList($linkUrl, $actions)
     {
     {
-        echo "Queuing for indexing: $linkUrl\n";
+        Log::info(
+            "Queuing for processing: $linkUrl"
+            . ' (' . implode(',', $actions) . ')'
+        );
+
         $this->gmclient->doBackground(
         $this->gmclient->doBackground(
-            'phinde_index',
+            $this->queueName,
             serialize(
                 array(
             serialize(
                 array(
-                    'url'    => $linkUrl,
-                    'title'  => $linkTitle,
-                    'source' => $sourceUrl
+                    'url'     => $linkUrl,
+                    'actions' => $actions,
                 )
             )
         );
         if ($this->gmclient->returnCode() != GEARMAN_SUCCESS) {
                 )
             )
         );
         if ($this->gmclient->returnCode() != GEARMAN_SUCCESS) {
-            echo 'Error queueing URL indexing for '
+            Log::error(
+                'Error queueing URL processing for '
                 . $linkUrl . "\n"
                 . $linkUrl . "\n"
-                . 'Error code: ' . $this->gmclient->returnCode() . "\n";
+                . 'Error code: ' . $this->gmclient->returnCode()
+            );
             exit(2);
         }
     }
 
             exit(2);
         }
     }
 
-    public function addToCrawl($linkUrl)
+    public function getServerStatus()
     {
     {
-        echo "Queuing for crawling: $linkUrl\n";
-        $this->gmclient->doBackground(
-            'phinde_crawl',
-            serialize(
-                array(
-                    'url' => $linkUrl
-                )
-            )
-        );
-        if ($this->gmclient->returnCode() != GEARMAN_SUCCESS) {
-            echo 'Error queueing URL crawling for '
-                . $linkUrl . "\n"
-                . 'Error code: ' . $this->gmclient->returnCode() . "\n";
-            exit(2);
+        $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],
+        );
     }
 }
 ?>
     }
 }
 ?>