@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.

Allow a HarbormasterBuildMessage to be sent to any object

Summary:
See T13054. This prepares for Buildables to be sent messages ("attach", "done scheduling builds") to fix races between Harbormaster and Differential.

The `buildTargetPHID` is replaced with a `recipientPHID` in the API. An additional change will fix the storage.

In the future, this table could probably also replace `HarbormasterBuildCommand` now, which is approximately the same bus, but for Builds.

Test Plan: Viewed builds with messages. Sent messages with `harbormaster.sendmessage`. Processed messages with `bin/phd debug task`.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

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

+53 -47
+1 -1
src/applications/harbormaster/conduit/HarbormasterSendMessageConduitAPIMethod.php
··· 245 245 } 246 246 247 247 $save[] = HarbormasterBuildMessage::initializeNewMessage($viewer) 248 - ->setBuildTargetPHID($build_target->getPHID()) 248 + ->setReceiverPHID($build_target->getPHID()) 249 249 ->setType($message_type); 250 250 251 251 $build_target->openTransaction();
+2 -2
src/applications/harbormaster/controller/HarbormasterBuildViewController.php
··· 65 65 if ($build_targets) { 66 66 $messages = id(new HarbormasterBuildMessageQuery()) 67 67 ->setViewer($viewer) 68 - ->withBuildTargetPHIDs(mpull($build_targets, 'getPHID')) 68 + ->withReceiverPHIDs(mpull($build_targets, 'getPHID')) 69 69 ->execute(); 70 - $messages = mgroup($messages, 'getBuildTargetPHID'); 70 + $messages = mgroup($messages, 'getReceiverPHID'); 71 71 } else { 72 72 $messages = array(); 73 73 }
+2 -2
src/applications/harbormaster/engine/HarbormasterBuildEngine.php
··· 382 382 383 383 $messages = id(new HarbormasterBuildMessageQuery()) 384 384 ->setViewer($this->getViewer()) 385 - ->withBuildTargetPHIDs(array_keys($waiting_targets)) 385 + ->withReceiverPHIDs(array_keys($waiting_targets)) 386 386 ->withConsumed(false) 387 387 ->execute(); 388 388 389 389 foreach ($messages as $message) { 390 - $target = $waiting_targets[$message->getBuildTargetPHID()]; 390 + $target = $waiting_targets[$message->getReceiverPHID()]; 391 391 392 392 switch ($message->getType()) { 393 393 case HarbormasterMessageType::MESSAGE_PASS:
+29 -35
src/applications/harbormaster/query/HarbormasterBuildMessageQuery.php
··· 4 4 extends PhabricatorCursorPagedPolicyAwareQuery { 5 5 6 6 private $ids; 7 - private $buildTargetPHIDs; 7 + private $receiverPHIDs; 8 8 private $consumed; 9 9 10 10 public function withIDs(array $ids) { ··· 12 12 return $this; 13 13 } 14 14 15 - public function withBuildTargetPHIDs(array $phids) { 16 - $this->buildTargetPHIDs = $phids; 15 + public function withReceiverPHIDs(array $phids) { 16 + $this->receiverPHIDs = $phids; 17 17 return $this; 18 18 } 19 19 ··· 22 22 return $this; 23 23 } 24 24 25 - protected function loadPage() { 26 - $table = new HarbormasterBuildMessage(); 27 - $conn_r = $table->establishConnection('r'); 28 - 29 - $data = queryfx_all( 30 - $conn_r, 31 - 'SELECT * FROM %T %Q %Q %Q', 32 - $table->getTableName(), 33 - $this->buildWhereClause($conn_r), 34 - $this->buildOrderClause($conn_r), 35 - $this->buildLimitClause($conn_r)); 25 + public function newResultObject() { 26 + return new HarbormasterBuildMessage(); 27 + } 36 28 37 - return $table->loadAllFromArray($data); 29 + protected function loadPage() { 30 + return $this->loadStandardPage($this->newResultObject()); 38 31 } 39 32 40 33 protected function willFilterPage(array $page) { 41 - $build_target_phids = array_filter(mpull($page, 'getBuildTargetPHID')); 42 - if ($build_target_phids) { 43 - $build_targets = id(new PhabricatorObjectQuery()) 34 + $receiver_phids = array_filter(mpull($page, 'getReceiverPHID')); 35 + if ($receiver_phids) { 36 + $receivers = id(new PhabricatorObjectQuery()) 44 37 ->setViewer($this->getViewer()) 45 - ->withPHIDs($build_target_phids) 38 + ->withPHIDs($receiver_phids) 46 39 ->setParentQuery($this) 47 40 ->execute(); 48 - $build_targets = mpull($build_targets, null, 'getPHID'); 41 + $receivers = mpull($receivers, null, 'getPHID'); 49 42 } else { 50 - $build_targets = array(); 43 + $receivers = array(); 51 44 } 52 45 53 46 foreach ($page as $key => $message) { 54 - $build_target_phid = $message->getBuildTargetPHID(); 55 - if (empty($build_targets[$build_target_phid])) { 47 + $receiver_phid = $message->getReceiverPHID(); 48 + 49 + if (empty($receivers[$receiver_phid])) { 56 50 unset($page[$key]); 51 + $this->didRejectResult($message); 57 52 continue; 58 53 } 59 - $message->attachBuildTarget($build_targets[$build_target_phid]); 54 + 55 + $message->attachReceiver($receivers[$receiver_phid]); 60 56 } 61 57 62 58 return $page; 63 59 } 64 60 65 - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 66 - $where = array(); 61 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 62 + $where = parent::buildWhereClauseParts($conn); 67 63 68 - if ($this->ids) { 64 + if ($this->ids !== null) { 69 65 $where[] = qsprintf( 70 - $conn_r, 66 + $conn, 71 67 'id IN (%Ld)', 72 68 $this->ids); 73 69 } 74 70 75 - if ($this->buildTargetPHIDs) { 71 + if ($this->receiverPHIDs !== null) { 76 72 $where[] = qsprintf( 77 - $conn_r, 73 + $conn, 78 74 'buildTargetPHID IN (%Ls)', 79 - $this->buildTargetPHIDs); 75 + $this->receiverPHIDs); 80 76 } 81 77 82 78 if ($this->consumed !== null) { 83 79 $where[] = qsprintf( 84 - $conn_r, 80 + $conn, 85 81 'isConsumed = %d', 86 82 (int)$this->consumed); 87 83 } 88 84 89 - $where[] = $this->buildPagingClause($conn_r); 90 - 91 - return $this->formatWhereClause($where); 85 + return $where; 92 86 } 93 87 94 88 public function getQueryApplicationClass() {
+19 -7
src/applications/harbormaster/storage/HarbormasterBuildMessage.php
··· 14 14 protected $type; 15 15 protected $isConsumed; 16 16 17 - private $buildTarget = self::ATTACHABLE; 17 + private $receiver = self::ATTACHABLE; 18 18 19 19 public static function initializeNewMessage(PhabricatorUser $actor) { 20 20 $actor_phid = $actor->getPHID(); ··· 41 41 ) + parent::getConfiguration(); 42 42 } 43 43 44 + public function getReceiverPHID() { 45 + return $this->getBuildTargetPHID(); 46 + } 47 + 48 + public function setReceiverPHID($phid) { 49 + return $this->setBuildTargetPHID($phid); 50 + } 51 + 52 + public function getReceiver() { 53 + return $this->assertAttached($this->receiver); 54 + } 55 + 44 56 public function getBuildTarget() { 45 - return $this->assertAttached($this->buildTarget); 57 + return $this->getReceiver(); 46 58 } 47 59 48 - public function attachBuildTarget(HarbormasterBuildTarget $target) { 49 - $this->buildTarget = $target; 60 + public function attachReceiver($receiver) { 61 + $this->receiver = $receiver; 50 62 return $this; 51 63 } 52 64 ··· 61 73 } 62 74 63 75 public function getPolicy($capability) { 64 - return $this->getBuildTarget()->getPolicy($capability); 76 + return $this->getReceiver()->getPolicy($capability); 65 77 } 66 78 67 79 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 68 - return $this->getBuildTarget()->hasAutomaticCapability( 80 + return $this->getReceiver()->hasAutomaticCapability( 69 81 $capability, 70 82 $viewer); 71 83 } 72 84 73 85 public function describeAutomaticCapability($capability) { 74 - return pht('Build messages have the same policies as their targets.'); 86 + return pht('Build messages have the same policies as their receivers.'); 75 87 } 76 88 77 89 }