Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/worker/PhabricatorSearchWorker.php
<?php | <?php | ||||
final class PhabricatorSearchWorker extends PhabricatorWorker { | final class PhabricatorSearchWorker extends PhabricatorWorker { | ||||
public static function queueDocumentForIndexing($phid, $context = null) { | public static function queueDocumentForIndexing($phid, $parameters = null) { | ||||
if ($parameters === null) { | |||||
$parameters = array(); | |||||
} | |||||
parent::scheduleTask( | parent::scheduleTask( | ||||
__CLASS__, | __CLASS__, | ||||
array( | array( | ||||
'documentPHID' => $phid, | 'documentPHID' => $phid, | ||||
'context' => $context, | 'parameters' => $parameters, | ||||
), | ), | ||||
array( | array( | ||||
'priority' => parent::PRIORITY_IMPORT, | 'priority' => parent::PRIORITY_IMPORT, | ||||
)); | )); | ||||
} | } | ||||
protected function doWork() { | protected function doWork() { | ||||
$data = $this->getTaskData(); | $data = $this->getTaskData(); | ||||
$object_phid = idx($data, 'documentPHID'); | $object_phid = idx($data, 'documentPHID'); | ||||
$context = idx($data, 'context'); | |||||
$engine = new PhabricatorIndexEngine(); | $object = $this->loadObjectForIndexing($object_phid); | ||||
$engine = id(new PhabricatorIndexEngine()) | |||||
->setObject($object); | |||||
$parameters = idx($data, 'parameters', array()); | |||||
$engine->setParameters($parameters); | |||||
if (!$engine->shouldIndexObject()) { | |||||
return; | |||||
} | |||||
$key = "index.{$object_phid}"; | $key = "index.{$object_phid}"; | ||||
$lock = PhabricatorGlobalLock::newLock($key); | $lock = PhabricatorGlobalLock::newLock($key); | ||||
$lock->lock(1); | $lock->lock(1); | ||||
try { | try { | ||||
$object = $this->loadObjectForIndexing($object_phid); | // Reload the object now that we have a lock, to make sure we have the | ||||
// most current version. | |||||
$object = $this->loadObjectForIndexing($object->getPHID()); | |||||
$engine->setObject($object); | |||||
$engine->indexDocumentByPHID($object->getPHID(), $context); | $engine->indexObject(); | ||||
$engine->indexDocumentByPHID($object->getPHID()); | |||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
$lock->unlock(); | $lock->unlock(); | ||||
if (!($ex instanceof PhabricatorWorkerPermanentFailureException)) { | if (!($ex instanceof PhabricatorWorkerPermanentFailureException)) { | ||||
$ex = new PhabricatorWorkerPermanentFailureException( | $ex = new PhabricatorWorkerPermanentFailureException( | ||||
pht( | pht( | ||||
'Failed to update search index for document "%s": %s', | 'Failed to update search index for document "%s": %s', | ||||
$object_phid, | $object_phid, | ||||
Show All 28 Lines |