mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-27 14:09:11 +01:00
Update buildable containerPHIDs in a proper way via BuildWorker rather than via sneaky uncoordinated write
Summary: Depends on D19065. Ref T13054. Instead of just updating `containerPHID` and hoping for the best, queue a proper BuildWorker to process a "your container has changed, update it" message. We also need to remove a (superfluous) `withContainerPHIDs()` when loading active diffs for a revision. Test Plan: - Without daemons, created a revision and saw builds stick in "preparing" with no container PHID, but also stay in draft mode. - With daemons, saw builds actually build and get the right container PHID. Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13054 Differential Revision: https://secure.phabricator.com/D19066
This commit is contained in:
parent
66f20595e4
commit
6f508a2258
4 changed files with 36 additions and 16 deletions
|
@ -365,21 +365,22 @@ final class DifferentialTransactionEditor
|
||||||
$diff->setRevisionID($object->getID());
|
$diff->setRevisionID($object->getID());
|
||||||
$diff->save();
|
$diff->save();
|
||||||
|
|
||||||
// Update Harbormaster to set the containerPHID correctly for any
|
// If there are any outstanding buildables for this diff, tell
|
||||||
// existing buildables. We may otherwise have buildables stuck with
|
// Harbormaster that their containers need to be updated. This is
|
||||||
// the old (`null`) container.
|
// common, because `arc` creates buildables so it can upload lint
|
||||||
|
// and unit results.
|
||||||
|
|
||||||
// TODO: This is a bit iffy, maybe we can find a cleaner approach?
|
$buildables = id(new HarbormasterBuildableQuery())
|
||||||
// In particular, this could (rarely) be overwritten by Harbormaster
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||||
// workers.
|
->withManualBuildables(false)
|
||||||
$table = new HarbormasterBuildable();
|
->withBuildablePHIDs(array($diff->getPHID()))
|
||||||
$conn_w = $table->establishConnection('w');
|
->execute();
|
||||||
queryfx(
|
foreach ($buildables as $buildable) {
|
||||||
$conn_w,
|
$buildable->sendMessage(
|
||||||
'UPDATE %T SET containerPHID = %s WHERE buildablePHID = %s',
|
$this->getActor(),
|
||||||
$table->getTableName(),
|
HarbormasterMessageType::BUILDABLE_CONTAINER,
|
||||||
$object->getPHID(),
|
true);
|
||||||
$diff->getPHID());
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -743,9 +743,10 @@ final class DifferentialRevision extends DifferentialDAO
|
||||||
public function loadActiveBuilds(PhabricatorUser $viewer) {
|
public function loadActiveBuilds(PhabricatorUser $viewer) {
|
||||||
$diff = $this->getActiveDiff();
|
$diff = $this->getActiveDiff();
|
||||||
|
|
||||||
|
// NOTE: We can't use `withContainerPHIDs()` here because the container
|
||||||
|
// update in Harbormaster is not synchronous.
|
||||||
$buildables = id(new HarbormasterBuildableQuery())
|
$buildables = id(new HarbormasterBuildableQuery())
|
||||||
->setViewer($viewer)
|
->setViewer($viewer)
|
||||||
->withContainerPHIDs(array($this->getPHID()))
|
|
||||||
->withBuildablePHIDs(array($diff->getPHID()))
|
->withBuildablePHIDs(array($diff->getPHID()))
|
||||||
->withManualBuildables(false)
|
->withManualBuildables(false)
|
||||||
->execute();
|
->execute();
|
||||||
|
|
|
@ -447,11 +447,15 @@ final class HarbormasterBuildEngine extends Phobject {
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
$done_preparing = false;
|
$done_preparing = false;
|
||||||
|
$update_container = false;
|
||||||
foreach ($messages as $message) {
|
foreach ($messages as $message) {
|
||||||
switch ($message->getType()) {
|
switch ($message->getType()) {
|
||||||
case HarbormasterMessageType::BUILDABLE_BUILD:
|
case HarbormasterMessageType::BUILDABLE_BUILD:
|
||||||
$done_preparing = true;
|
$done_preparing = true;
|
||||||
break;
|
break;
|
||||||
|
case HarbormasterMessageType::BUILDABLE_CONTAINER:
|
||||||
|
$update_container = true;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -463,7 +467,6 @@ final class HarbormasterBuildEngine extends Phobject {
|
||||||
|
|
||||||
// If we received a "build" command, all builds are scheduled and we can
|
// If we received a "build" command, all builds are scheduled and we can
|
||||||
// move out of "preparing" into "building".
|
// move out of "preparing" into "building".
|
||||||
|
|
||||||
if ($done_preparing) {
|
if ($done_preparing) {
|
||||||
if ($buildable->isPreparing()) {
|
if ($buildable->isPreparing()) {
|
||||||
$buildable
|
$buildable
|
||||||
|
@ -472,6 +475,20 @@ final class HarbormasterBuildEngine extends Phobject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we've been informed that the container for the buildable has
|
||||||
|
// changed, update it.
|
||||||
|
if ($update_container) {
|
||||||
|
$object = id(new PhabricatorObjectQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withPHIDs(array($buildable->getBuildablePHID()))
|
||||||
|
->executeOne();
|
||||||
|
if ($object) {
|
||||||
|
$buildable
|
||||||
|
->setContainerPHID($object->getHarbormasterContainerPHID())
|
||||||
|
->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Don't update the buildable status if we're still preparing builds: more
|
// Don't update the buildable status if we're still preparing builds: more
|
||||||
// builds may still be scheduled shortly, so even if every build we know
|
// builds may still be scheduled shortly, so even if every build we know
|
||||||
// about so far has passed, that doesn't mean the buildable has actually
|
// about so far has passed, that doesn't mean the buildable has actually
|
||||||
|
|
|
@ -7,6 +7,7 @@ final class HarbormasterMessageType extends Phobject {
|
||||||
const MESSAGE_WORK = 'work';
|
const MESSAGE_WORK = 'work';
|
||||||
|
|
||||||
const BUILDABLE_BUILD = 'build';
|
const BUILDABLE_BUILD = 'build';
|
||||||
|
const BUILDABLE_CONTAINER = 'container';
|
||||||
|
|
||||||
public static function getAllMessages() {
|
public static function getAllMessages() {
|
||||||
return array_keys(self::getMessageSpecifications());
|
return array_keys(self::getMessageSpecifications());
|
||||||
|
|
Loading…
Add table
Reference in a new issue