Fix date searches
[phinde.git] / bin / phinde-worker.php
index e8253ff945c9e83f07686a50f84db0d4f9bef939..9b65e324d679c0dcbe2f61932aadfb80e090df3c 100755 (executable)
@@ -4,30 +4,38 @@ namespace phinde;
 
 chdir(dirname($argv[0]));
 
+require_once __DIR__ . '/../src/init.php';
+
 $gmworker = new \GearmanWorker();
 $gmworker->addServer('127.0.0.1');
 
 $gmworker->addFunction(
-    'phinde_crawl',
+    $GLOBALS['phinde']['queuePrefix'] . 'phinde_process',
     function(\GearmanJob $job) {
         $data = unserialize($job->workload());
-        echo "-- Crawling " . $data['url'] . "\n";
-        passthru('./crawl.php ' . escapeshellarg($data['url']));
+        Log::info(
+            "-- Processing " . $data['url']
+            . ' (' . implode(',', $data['actions']) . ')'
+        );
+        passthru(
+            './process.php ' . escapeshellarg($data['url'])
+            . ' ' . implode(' ', $data['actions'])
+        );
     }
 );
+
 $gmworker->addFunction(
-    'phinde_index',
+    $GLOBALS['phinde']['queuePrefix'] . 'phinde_quit',
     function(\GearmanJob $job) {
-        $data = unserialize($job->workload());
-        echo "-- Indexing " . $data['url'] . "\n";
-        passthru('./index.php ' . escapeshellarg($data['url']));
-        //exit();
+        Log::info('Got exit job');
+        $job->sendComplete('');
+        exit(0);
     }
 );
 
 while ($gmworker->work()) {
     if ($gmworker->returnCode() != GEARMAN_SUCCESS) {
-        echo 'Error running job: ' . $gmworker->returnCode() . "\n";
+        Log::error('Error running job: ' . $gmworker->returnCode());
         break;
     }
 }