silverstripe-fulltextsearch/code/solr/reindex/handlers/SolrReindexMessageHandler.php

45 lines
1.2 KiB
PHP
Raw Normal View History

<?php
use Psr\Log\LoggerInterface;
2015-11-21 07:19:20 +01:00
if (!class_exists('MessageQueue')) {
return;
}
2015-11-21 07:19:20 +01:00
class SolrReindexMessageHandler extends SolrReindexImmediateHandler
{
/**
* The MessageQueue to use when processing updates
* @config
* @var string
*/
private static $reindex_queue = "search_indexing";
2015-11-21 07:19:20 +01:00
public function triggerReindex(LoggerInterface $logger, $batchSize, $taskName, $classes = null)
{
$queue = Config::inst()->get(__CLASS__, 'reindex_queue');
2015-11-21 07:19:20 +01:00
$logger->info('Queuing message');
MessageQueue::send(
$queue,
new MethodInvocationMessage('SolrReindexMessageHandler', 'run_reindex', $batchSize, $taskName, $classes)
);
}
2015-11-21 07:19:20 +01:00
/**
* Entry point for message queue
*
* @param int $batchSize
* @param string $taskName
* @param array|string|null $classes
*/
public static function run_reindex($batchSize, $taskName, $classes = null)
{
// @todo Logger for message queue?
$logger = Injector::inst()->createWithArgs('Monolog\Logger', array(strtolower(get_class())));
$inst = Injector::inst()->get(get_class());
$inst->runReindex($logger, $batchSize, $taskName, $classes);
}
}