-
Notifications
You must be signed in to change notification settings - Fork 83
/
SearchUpdateQueuedJobProcessor.php
108 lines (86 loc) · 2.67 KB
/
SearchUpdateQueuedJobProcessor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace SilverStripe\FullTextSearch\Search\Processors;
use SilverStripe\Core\Config\Config;
use stdClass;
use Symbiote\QueuedJobs\Services\QueuedJob;
use Symbiote\QueuedJobs\Services\QueuedJobService;
if (!interface_exists(QueuedJob::class)) {
return;
}
class SearchUpdateQueuedJobProcessor extends SearchUpdateBatchedProcessor implements QueuedJob
{
/**
* The QueuedJob queue to use when processing updates
* @config
* @var string
*/
private static $reindex_queue = QueuedJob::QUEUED;
protected $messages = array();
public function triggerProcessing()
{
parent::triggerProcessing();
singleton(QueuedJobService::class)->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(__CLASS__, 'reindex_queue');
}
public function jobFinished()
{
return $this->currentBatch >= count($this->batches ?? []);
}
public function setup()
{
// NOP
}
public function prepareForRestart()
{
// NOP
}
public function afterComplete()
{
// 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();
}
public function getJobData()
{
$data = new stdClass();
$data->totalSteps = count($this->batches ?? []);
$data->currentStep = $this->currentBatch;
$data->isComplete = $this->jobFinished();
$data->messages = $this->messages;
$data->jobData = new stdClass();
$data->jobData->batches = $this->batches;
$data->jobData->currentBatch = $this->currentBatch;
return $data;
}
public function setJobData($totalSteps, $currentStep, $isComplete, $jobData, $messages)
{
$this->isComplete = $isComplete;
$this->messages = $messages;
$this->batches = $jobData->batches;
$this->currentBatch = $jobData->currentBatch;
}
public function addMessage($message, $severity = 'INFO')
{
$severity = strtoupper($severity ?? '');
$this->messages[] = '[' . date('Y-m-d H:i:s') . "][$severity] $message";
}
public function process()
{
$result = parent::process();
if ($this->jobFinished()) {
$this->addMessage("All batched updates complete. Queuing commit job");
}
return $result;
}
}