Source of file SolrReindexQueuedHandler.php
Size: 4,018 Bytes - Last Modified: 2021-12-23T10:52:39+00:00
/var/www/docs.ssmods.com/process/src/src/Solr/Reindex/Handlers/SolrReindexQueuedHandler.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 | <?php namespace SilverStripe\FullTextSearch\Solr\Reindex\Handlers; use Psr\Log\LoggerInterface; use SilverStripe\FullTextSearch\Solr\SolrIndex; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DB; use SilverStripe\Core\Convert; use SilverStripe\Core\Injector\Injector; use SilverStripe\FullTextSearch\Solr\Reindex\Jobs\SolrReindexQueuedJob; use SilverStripe\FullTextSearch\Solr\Reindex\Jobs\SolrReindexGroupQueuedJob; use SilverStripe\FullTextSearch\Search\Processors\SearchUpdateCommitJobProcessor; use Symbiote\QueuedJobs\Services\QueuedJob; use Symbiote\QueuedJobs\Services\QueuedJobService; use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor; if (!interface_exists(QueuedJob::class)) { return; } /** * Represents a queued task to start the reindex job */ class SolrReindexQueuedHandler extends SolrReindexBase { /** * @return QueuedJobService */ protected function getQueuedJobService() { return singleton(QueuedJobService::class); } /** * Cancel any cancellable jobs * * @param string $type Type of job to cancel * @return int Number of jobs cleared */ protected function cancelExistingJobs($type) { $clearable = array( // Paused jobs need to be discarded QueuedJob::STATUS_PAUSED, // These types would be automatically started QueuedJob::STATUS_NEW, QueuedJob::STATUS_WAIT, // Cancel any in-progress job QueuedJob::STATUS_INIT, QueuedJob::STATUS_RUN ); DB::query(sprintf( 'UPDATE "%s" ' . ' SET "JobStatus" = \'%s\'' . ' WHERE "JobStatus" IN (\'%s\')' . ' AND "Implementation" = \'%s\'', Convert::raw2sql(DataObject::getSchema()->tableName(QueuedJobDescriptor::class)), Convert::raw2sql(QueuedJob::STATUS_CANCELLED), implode("','", Convert::raw2sql($clearable)), Convert::raw2sql($type) )); return DB::affected_rows(); } public function triggerReindex(LoggerInterface $logger, $batchSize, $taskName, $classes = null) { // Cancel existing jobs $queues = $this->cancelExistingJobs(SolrReindexQueuedJob::class); $groups = $this->cancelExistingJobs(SolrReindexGroupQueuedJob::class); $logger->info("Cancelled {$queues} re-index tasks and {$groups} re-index groups"); // Although this class is used as a service (singleton) it may also be instantiated // as a queuedjob $job = Injector::inst()->create(SolrReindexQueuedJob::class, $batchSize, $taskName, $classes); $this ->getQueuedJobService() ->queueJob($job); $title = $job->getTitle(); $logger->info("Queued {$title}"); } protected function processGroup( LoggerInterface $logger, SolrIndex $indexInstance, $state, $class, $groups, $group, $taskName ) { // Trigger another job for this group $job = Injector::inst()->create( SolrReindexGroupQueuedJob::class, get_class($indexInstance), $state, $class, $groups, $group ); $this ->getQueuedJobService() ->queueJob($job); $title = $job->getTitle(); $logger->info("Queued {$title}"); } public function runGroup( LoggerInterface $logger, SolrIndex $indexInstance, $state, $class, $groups, $group ) { parent::runGroup($logger, $indexInstance, $state, $class, $groups, $group); // After any changes have been made, mark all indexes as dirty for commit // see http://stackoverflow.com/questions/7512945/how-to-fix-exceeded-limit-of-maxwarmingsearchers $logger->info("Queuing commit on all changes"); SearchUpdateCommitJobProcessor::queue(); } } |