From f77dad8f1dda382a23b9d22393e239be6c087a07 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Tue, 30 Aug 2016 13:10:03 +0200 Subject: [PATCH] Allow worker instances of multiple projects in parallel Change "queuePrefix" configuration in each project Resolves: #5 --- bin/phinde-worker.php | 4 ++-- data/config.php.dist | 3 +++ src/phinde/Queue.php | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bin/phinde-worker.php b/bin/phinde-worker.php index 7adb7af..939db1f 100755 --- a/bin/phinde-worker.php +++ b/bin/phinde-worker.php @@ -32,7 +32,7 @@ $gmworker->addServer('127.0.0.1'); if (isset($queues['crawl'])) { $gmworker->addFunction( - 'phinde_crawl', + $GLOBALS['phinde']['queuePrefix'] . 'phinde_crawl', function(\GearmanJob $job) { $data = unserialize($job->workload()); echo "-- Crawling " . $data['url'] . "\n"; @@ -42,7 +42,7 @@ if (isset($queues['crawl'])) { } if (isset($queues['index'])) { $gmworker->addFunction( - 'phinde_index', + $GLOBALS['phinde']['queuePrefix'] . 'phinde_index', function(\GearmanJob $job) { $data = unserialize($job->workload()); echo "-- Indexing " . $data['url'] . "\n"; diff --git a/data/config.php.dist b/data/config.php.dist index dc1cff8..3c1ccea 100644 --- a/data/config.php.dist +++ b/data/config.php.dist @@ -19,5 +19,8 @@ $GLOBALS['phinde'] = array( //if directly linked URLs shall be indexed, even if they are // on a non-whitelisted domain 'indexNonAllowed' => true, + //prefix for the gearman queue names, needed when multiple instances + //are running in parallel + 'queuePrefix' => '', ); ?> \ No newline at end of file diff --git a/src/phinde/Queue.php b/src/phinde/Queue.php index 98f6462..406f27e 100644 --- a/src/phinde/Queue.php +++ b/src/phinde/Queue.php @@ -15,7 +15,7 @@ class Queue { echo "Queuing for indexing: $linkUrl\n"; $this->gmclient->doBackground( - 'phinde_index', + $GLOBALS['phinde']['queuePrefix'] . 'phinde_index', serialize( array( 'url' => $linkUrl, @@ -36,7 +36,7 @@ class Queue { echo "Queuing for crawling: $linkUrl\n"; $this->gmclient->doBackground( - 'phinde_crawl', + $GLOBALS['phinde']['queuePrefix'] . 'phinde_crawl', serialize( array( 'url' => $linkUrl -- 2.30.2