2013-07-25 04:27:09 +02:00
|
|
|
<?php
|
|
|
|
|
2014-05-16 07:42:08 +02:00
|
|
|
if(!interface_exists('QueuedJob')) return;
|
2013-07-25 04:27:09 +02:00
|
|
|
|
2014-05-16 07:42:08 +02:00
|
|
|
class SearchUpdateQueuedJobProcessor extends SearchUpdateBatchedProcessor implements QueuedJob {
|
2013-07-25 04:27:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The QueuedJob queue to use when processing updates
|
|
|
|
* @config
|
2015-05-07 05:16:27 +02:00
|
|
|
* @var int
|
2013-07-25 04:27:09 +02:00
|
|
|
*/
|
|
|
|
private static $reindex_queue = 2; // QueuedJob::QUEUED;
|
|
|
|
|
|
|
|
protected $messages = array();
|
|
|
|
|
|
|
|
public function triggerProcessing() {
|
2014-05-16 07:42:08 +02:00
|
|
|
parent::triggerProcessing();
|
2013-07-25 04:27:09 +02:00
|
|
|
singleton('QueuedJobService')->queueJob($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTitle() {
|
|
|
|
return "FullTextSearch Update Job";
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSignature() {
|
|
|
|
return md5(get_class($this) . time() . mt_rand(0, 100000));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getJobType() {
|
|
|
|
return Config::inst()->get('SearchUpdateQueuedJobProcessor', 'reindex_queue');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function jobFinished() {
|
2014-05-16 07:42:08 +02:00
|
|
|
return $this->currentBatch >= count($this->batches);
|
2013-07-25 04:27:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setup() {
|
2014-05-16 07:42:08 +02:00
|
|
|
// NOP
|
2013-07-25 04:27:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function prepareForRestart() {
|
|
|
|
// NOP
|
|
|
|
}
|
|
|
|
|
|
|
|
public function afterComplete() {
|
2015-05-07 05:16:27 +02:00
|
|
|
// Once indexing is complete, commit later in order to avoid solr limits
|
|
|
|
// see http://stackoverflow.com/questions/7512945/how-to-fix-exceeded-limit-of-maxwarmingsearchers
|
|
|
|
SearchUpdateCommitJobProcessor::queue();
|
2013-07-25 04:27:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getJobData() {
|
|
|
|
$data = new stdClass();
|
2014-05-16 07:42:08 +02:00
|
|
|
$data->totalSteps = count($this->batches);
|
|
|
|
$data->currentStep = $this->currentBatch;
|
|
|
|
$data->isComplete = $this->jobFinished();
|
2013-07-25 04:27:09 +02:00
|
|
|
$data->messages = $this->messages;
|
|
|
|
|
|
|
|
$data->jobData = new stdClass();
|
2014-05-16 07:42:08 +02:00
|
|
|
$data->jobData->batches = $this->batches;
|
|
|
|
$data->jobData->currentBatch = $this->currentBatch;
|
2013-07-25 04:27:09 +02:00
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setJobData($totalSteps, $currentStep, $isComplete, $jobData, $messages) {
|
|
|
|
$this->isComplete = $isComplete;
|
|
|
|
$this->messages = $messages;
|
|
|
|
|
2014-05-16 07:42:08 +02:00
|
|
|
$this->batches = $jobData->batches;
|
|
|
|
$this->currentBatch = $jobData->currentBatch;
|
2013-07-25 04:27:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function addMessage($message, $severity='INFO') {
|
|
|
|
$severity = strtoupper($severity);
|
|
|
|
$this->messages[] = '[' . date('Y-m-d H:i:s') . "][$severity] $message";
|
|
|
|
}
|
2015-05-07 05:16:27 +02:00
|
|
|
|
|
|
|
public function process() {
|
|
|
|
$result = parent::process();
|
|
|
|
|
|
|
|
if($this->jobFinished()) {
|
|
|
|
$this->addMessage("All batched updates complete. Queuing commit job");
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2013-07-25 04:27:09 +02:00
|
|
|
}
|