{
$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(
- $GLOBALS['phinde']['queuePrefix'] . 'phinde_index',
+ $this->queueName,
serialize(
array(
- 'url' => $linkUrl,
- 'title' => $linkTitle,
- 'source' => $sourceUrl
+ 'url' => $linkUrl,
+ 'actions' => $actions,
)
)
);
if ($this->gmclient->returnCode() != GEARMAN_SUCCESS) {
- echo 'Error queueing URL indexing for '
+ Log::error(
+ 'Error queueing URL processing for '
. $linkUrl . "\n"
- . 'Error code: ' . $this->gmclient->returnCode() . "\n";
+ . 'Error code: ' . $this->gmclient->returnCode()
+ );
exit(2);
}
}
- public function addToCrawl($linkUrl)
+ public function getServerStatus()
{
- echo "Queuing for crawling: $linkUrl\n";
- $this->gmclient->doBackground(
- $GLOBALS['phinde']['queuePrefix'] . '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],
+ );
}
}
?>