aboutsummaryrefslogtreecommitdiff
path: root/bin/phinde-worker.php
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2016-08-30 13:03:26 +0200
committerChristian Weiske <cweiske@cweiske.de>2016-08-30 13:03:26 +0200
commit1ba3122f581c4f2dd3e013673980c239287995d3 (patch)
tree70d6ede96bf53aef58b6818465444df8d8ccc587 /bin/phinde-worker.php
parent45638a5de3c8c05c1792f8a3ab93acb11a2c1a86 (diff)
downloadphinde-1ba3122f581c4f2dd3e013673980c239287995d3.tar.gz
phinde-1ba3122f581c4f2dd3e013673980c239287995d3.zip
Make phinde-worker configurable; allow queue selection
Resolves #6
Diffstat (limited to 'bin/phinde-worker.php')
-rwxr-xr-xbin/phinde-worker.php61
1 files changed, 44 insertions, 17 deletions
diff --git a/bin/phinde-worker.php b/bin/phinde-worker.php
index e8253ff..7adb7af 100755
--- a/bin/phinde-worker.php
+++ b/bin/phinde-worker.php
@@ -4,26 +4,53 @@ namespace phinde;
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');
-$gmworker->addFunction(
- 'phinde_crawl',
- function(\GearmanJob $job) {
- $data = unserialize($job->workload());
- echo "-- Crawling " . $data['url'] . "\n";
- passthru('./crawl.php ' . escapeshellarg($data['url']));
- }
-);
-$gmworker->addFunction(
- 'phinde_index',
- function(\GearmanJob $job) {
- $data = unserialize($job->workload());
- echo "-- Indexing " . $data['url'] . "\n";
- passthru('./index.php ' . escapeshellarg($data['url']));
- //exit();
- }
-);
+if (isset($queues['crawl'])) {
+ $gmworker->addFunction(
+ '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(
+ 'phinde_index',
+ function(\GearmanJob $job) {
+ $data = unserialize($job->workload());
+ echo "-- Indexing " . $data['url'] . "\n";
+ passthru('./index.php ' . escapeshellarg($data['url']));
+ //exit();
+ }
+ );
+}
while ($gmworker->work()) {
if ($gmworker->returnCode() != GEARMAN_SUCCESS) {