@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Refine error behavior of `bin/search index`

Summary: Fixes T5991. If //all requested documents// failed to index, consider this a catastrophic failure and exit with an error code.

Test Plan:
- Ran `bin/search index --type TASK`, observed successful exit despite a small number of un-indexable documents.
- Ran `bin/search index PHID-TASK-xxx` for an invalid task, observed exception on exit after complete failure.
- Ran normal indexing through daemons.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T5991

Differential Revision: https://secure.phabricator.com/D14174

+47 -44
+23 -41
src/applications/search/index/PhabricatorSearchDocumentIndexer.php
··· 42 42 } 43 43 44 44 public function indexDocumentByPHID($phid, $context) { 45 - try { 46 - $this->setContext($context); 45 + $this->setContext($context); 47 46 48 - $document = $this->buildAbstractDocumentByPHID($phid); 49 - if ($document === null) { 50 - // This indexer doesn't build a document index, so we're done. 51 - return $this; 52 - } 47 + $document = $this->buildAbstractDocumentByPHID($phid); 48 + if ($document === null) { 49 + // This indexer doesn't build a document index, so we're done. 50 + return $this; 51 + } 53 52 54 - $object = $this->loadDocumentByPHID($phid); 53 + $object = $this->loadDocumentByPHID($phid); 55 54 56 - // Automatically rebuild CustomField indexes if the object uses custom 57 - // fields. 58 - if ($object instanceof PhabricatorCustomFieldInterface) { 59 - $this->indexCustomFields($document, $object); 60 - } 55 + // Automatically rebuild CustomField indexes if the object uses custom 56 + // fields. 57 + if ($object instanceof PhabricatorCustomFieldInterface) { 58 + $this->indexCustomFields($document, $object); 59 + } 61 60 62 - // Automatically rebuild subscriber indexes if the object is subscribable. 63 - if ($object instanceof PhabricatorSubscribableInterface) { 64 - $this->indexSubscribers($document); 65 - } 61 + // Automatically rebuild subscriber indexes if the object is subscribable. 62 + if ($object instanceof PhabricatorSubscribableInterface) { 63 + $this->indexSubscribers($document); 64 + } 66 65 67 - // Automatically build project relationships 68 - if ($object instanceof PhabricatorProjectInterface) { 69 - $this->indexProjects($document, $object); 70 - } 66 + // Automatically build project relationships 67 + if ($object instanceof PhabricatorProjectInterface) { 68 + $this->indexProjects($document, $object); 69 + } 71 70 72 - $engine = PhabricatorSearchEngine::loadEngine(); 73 - try { 74 - $engine->reindexAbstractDocument($document); 75 - } catch (Exception $ex) { 76 - phlog( 77 - pht( 78 - 'Unable to index document %s with engine %s.', 79 - $document->getPHID(), 80 - get_class($engine))); 81 - phlog($ex); 82 - } 71 + $engine = PhabricatorSearchEngine::loadEngine(); 72 + $engine->reindexAbstractDocument($document); 83 73 84 - $this->dispatchDidUpdateIndexEvent($phid, $document); 85 - } catch (Exception $ex) { 86 - phlog( 87 - pht( 88 - 'Unable to build document %s with indexer %s.', 89 - $phid, 90 - get_class($this))); 91 - phlog($ex); 92 - } 74 + $this->dispatchDidUpdateIndexEvent($phid, $document); 93 75 94 76 return $this; 95 77 }
+14 -1
src/applications/search/management/PhabricatorSearchManagementIndexWorkflow.php
··· 93 93 $bar = id(new PhutilConsoleProgressBar()) 94 94 ->setTotal(count($phids)); 95 95 96 + $any_success = false; 96 97 $indexer = new PhabricatorSearchIndexer(); 97 98 foreach ($phids as $phid) { 98 - $indexer->queueDocumentForIndexing($phid); 99 + try { 100 + $indexer->queueDocumentForIndexing($phid); 101 + $any_success = true; 102 + } catch (Exception $ex) { 103 + phlog($ex); 104 + } 105 + 99 106 $bar->update(1); 100 107 } 101 108 102 109 $bar->done(); 110 + 111 + if (!$any_success) { 112 + throw new Exception( 113 + pht('Failed to rebuild search index for any documents.')); 114 + } 115 + 103 116 } 104 117 105 118 private function loadPHIDsByNames(array $names) {
+10 -2
src/applications/search/worker/PhabricatorSearchWorker.php
··· 8 8 $phid = idx($data, 'documentPHID'); 9 9 $context = idx($data, 'context'); 10 10 11 - id(new PhabricatorSearchIndexer()) 12 - ->indexDocumentByPHID($phid, $context); 11 + try { 12 + id(new PhabricatorSearchIndexer()) 13 + ->indexDocumentByPHID($phid, $context); 14 + } catch (Exception $ex) { 15 + throw new PhabricatorWorkerPermanentFailureException( 16 + pht( 17 + 'Failed to update search index for document "%s": %s', 18 + $phid, 19 + $ex->getMessage())); 20 + } 13 21 } 14 22 15 23 }