diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2016-11-07 21:41:36 +0100 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2016-11-07 21:41:36 +0100 |
| commit | d7651fd96dcfa2829519504e4c8ec1ce511cd57f (patch) | |
| tree | e24d7a9f90060b0fee5a652de43bd0627f1c5bde /bin/phinde-worker.php | |
| parent | f90790c6b2a54c9b1c8a0aeaf1f23e6aa67d7aca (diff) | |
| download | phinde-d7651fd96dcfa2829519504e4c8ec1ce511cd57f.tar.gz phinde-d7651fd96dcfa2829519504e4c8ec1ce511cd57f.zip | |
Big patch merging crawling+indexing into one command, new json document structure
Diffstat (limited to 'bin/phinde-worker.php')
| -rwxr-xr-x | bin/phinde-worker.php | 55 |
1 files changed, 13 insertions, 42 deletions
diff --git a/bin/phinde-worker.php b/bin/phinde-worker.php index 939db1f..1e94535 100755 --- a/bin/phinde-worker.php +++ b/bin/phinde-worker.php @@ -6,51 +6,22 @@ chdir(dirname($argv[0])); require_once __DIR__ . '/../src/init.php'; -$cc = new \Console_CommandLine(); -$cc->description = 'phinde queue worker'; -$cc->version = '0.0.1'; -$cc->addArgument( - 'queues', - array( - 'description' => 'Queue(s) to process', - 'multiple' => true, - 'default' => array('crawl', 'index'), - 'choices' => array('crawl', 'index'), - 'optional' => true, - ) -); -try { - $res = $cc->parse(); -} catch (\Exception $e) { - $cc->displayError($e->getMessage()); -} - -$queues = array_flip(array_unique($res->args['queues'])); - $gmworker = new \GearmanWorker(); $gmworker->addServer('127.0.0.1'); -if (isset($queues['crawl'])) { - $gmworker->addFunction( - $GLOBALS['phinde']['queuePrefix'] . 'phinde_crawl', - function(\GearmanJob $job) { - $data = unserialize($job->workload()); - echo "-- Crawling " . $data['url'] . "\n"; - passthru('./crawl.php ' . escapeshellarg($data['url'])); - } - ); -} -if (isset($queues['index'])) { - $gmworker->addFunction( - $GLOBALS['phinde']['queuePrefix'] . 'phinde_index', - function(\GearmanJob $job) { - $data = unserialize($job->workload()); - echo "-- Indexing " . $data['url'] . "\n"; - passthru('./index.php ' . escapeshellarg($data['url'])); - //exit(); - } - ); -} +$gmworker->addFunction( + $GLOBALS['phinde']['queuePrefix'] . 'phinde_process', + function(\GearmanJob $job) { + $data = unserialize($job->workload()); + echo "-- Processing " . $data['url'] + . ' (' . implode(',', $data['actions']) . ')' + . "\n"; + passthru( + './process.php ' . escapeshellarg($data['url']) + . ' ' . implode(' ', $data['actions']) + ); + } +); while ($gmworker->work()) { if ($gmworker->returnCode() != GEARMAN_SUCCESS) { |
