mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 21:40:55 +01:00
Merge the "HarbormasterBuildCommand" table into "HarbormasterBuildMessage"
Summary: Ref T13072. These two similar tables don't make sense to keep separate. Instead, make Build a valid receiver for BuildMessage objects. These tables are practically the same, so this is straightforward: just copy the rows in and then drop the old table. (This table was trivial and ephemeral anyway, so I'm not bothering to do the usual "keep it around for a couple years just in case".) Test Plan: - Populated BuildCommand table, ran migration, saw Builds end up in the proper transitional state (e.g., pausing, aborting, restarting) with appropriate queued messages. - Queued new messages by clicking UI buttons. - Ran BuildWorkers, saw them process messages and mark them as consumed. Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13072 Differential Revision: https://secure.phabricator.com/D21684
This commit is contained in:
parent
0f93d1ffe4
commit
b48d4fabaf
7 changed files with 26 additions and 32 deletions
|
@ -0,0 +1,4 @@
|
|||
INSERT IGNORE INTO {$NAMESPACE}_harbormaster.harbormaster_buildmessage
|
||||
(authorPHID, receiverPHID, type, isConsumed, dateCreated, dateModified)
|
||||
SELECT authorPHID, targetPHID, command, 0, dateCreated, dateModified
|
||||
FROM {$NAMESPACE}_harbormaster.harbormaster_buildcommand;
|
|
@ -0,0 +1 @@
|
|||
DROP TABLE IF EXISTS {$NAMESPACE}_harbormaster.harbormaster_buildcommand;
|
|
@ -7597,7 +7597,7 @@ phutil_register_library_map(array(
|
|||
'HarbormasterBuildArtifactPHIDType' => 'PhabricatorPHIDType',
|
||||
'HarbormasterBuildArtifactQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'HarbormasterBuildAutoplan' => 'Phobject',
|
||||
'HarbormasterBuildCommand' => 'HarbormasterDAO',
|
||||
'HarbormasterBuildCommand' => 'Phobject',
|
||||
'HarbormasterBuildDependencyDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'HarbormasterBuildEngine' => 'Phobject',
|
||||
'HarbormasterBuildFailureException' => 'Exception',
|
||||
|
|
|
@ -93,10 +93,10 @@ final class HarbormasterBuildTransactionEditor
|
|||
return;
|
||||
}
|
||||
|
||||
id(new HarbormasterBuildCommand())
|
||||
HarbormasterBuildMessage::initializeNewMessage($actor)
|
||||
->setAuthorPHID($xaction->getAuthorPHID())
|
||||
->setTargetPHID($build->getPHID())
|
||||
->setCommand($command)
|
||||
->setReceiverPHID($build->getPHID())
|
||||
->setType($command)
|
||||
->save();
|
||||
|
||||
PhabricatorWorker::scheduleTask(
|
||||
|
|
|
@ -104,10 +104,10 @@ final class HarbormasterBuildQuery
|
|||
}
|
||||
|
||||
$build_phids = mpull($page, 'getPHID');
|
||||
$messages = id(new HarbormasterBuildCommand())->loadAllWhere(
|
||||
'targetPHID IN (%Ls) ORDER BY id ASC',
|
||||
$messages = id(new HarbormasterBuildMessage())->loadAllWhere(
|
||||
'receiverPHID IN (%Ls) AND isConsumed = 0 ORDER BY id ASC',
|
||||
$build_phids);
|
||||
$messages = mgroup($messages, 'getTargetPHID');
|
||||
$messages = mgroup($messages, 'getReceiverPHID');
|
||||
foreach ($page as $build) {
|
||||
$unprocessed_messages = idx($messages, $build->getPHID(), array());
|
||||
$build->attachUnprocessedMessages($unprocessed_messages);
|
||||
|
|
|
@ -1,27 +1,11 @@
|
|||
<?php
|
||||
|
||||
final class HarbormasterBuildCommand extends HarbormasterDAO {
|
||||
final class HarbormasterBuildCommand
|
||||
extends Phobject {
|
||||
|
||||
const COMMAND_PAUSE = 'pause';
|
||||
const COMMAND_RESUME = 'resume';
|
||||
const COMMAND_RESTART = 'restart';
|
||||
const COMMAND_ABORT = 'abort';
|
||||
|
||||
protected $authorPHID;
|
||||
protected $targetPHID;
|
||||
protected $command;
|
||||
|
||||
protected function getConfiguration() {
|
||||
return array(
|
||||
self::CONFIG_COLUMN_SCHEMA => array(
|
||||
'command' => 'text128',
|
||||
),
|
||||
self::CONFIG_KEY_SCHEMA => array(
|
||||
'key_target' => array(
|
||||
'columns' => array('targetPHID'),
|
||||
),
|
||||
),
|
||||
) + parent::getConfiguration();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -230,6 +230,7 @@ final class HarbormasterBuild extends HarbormasterDAO
|
|||
}
|
||||
|
||||
public function attachUnprocessedMessages(array $messages) {
|
||||
assert_instances_of($messages, 'HarbormasterBuildMessage');
|
||||
$this->unprocessedMessages = $messages;
|
||||
return $this;
|
||||
}
|
||||
|
@ -331,7 +332,7 @@ final class HarbormasterBuild extends HarbormasterDAO
|
|||
public function isPausing() {
|
||||
$is_pausing = false;
|
||||
foreach ($this->getUnprocessedMessages() as $message_object) {
|
||||
$message_type = $message_object->getCommand();
|
||||
$message_type = $message_object->getType();
|
||||
switch ($message_type) {
|
||||
case HarbormasterBuildCommand::COMMAND_PAUSE:
|
||||
$is_pausing = true;
|
||||
|
@ -352,7 +353,7 @@ final class HarbormasterBuild extends HarbormasterDAO
|
|||
public function isResuming() {
|
||||
$is_resuming = false;
|
||||
foreach ($this->getUnprocessedMessages() as $message_object) {
|
||||
$message_type = $message_object->getCommand();
|
||||
$message_type = $message_object->getType();
|
||||
switch ($message_type) {
|
||||
case HarbormasterBuildCommand::COMMAND_RESTART:
|
||||
case HarbormasterBuildCommand::COMMAND_RESUME:
|
||||
|
@ -373,7 +374,7 @@ final class HarbormasterBuild extends HarbormasterDAO
|
|||
public function isRestarting() {
|
||||
$is_restarting = false;
|
||||
foreach ($this->getUnprocessedMessages() as $message_object) {
|
||||
$message_type = $message_object->getCommand();
|
||||
$message_type = $message_object->getType();
|
||||
switch ($message_type) {
|
||||
case HarbormasterBuildCommand::COMMAND_RESTART:
|
||||
$is_restarting = true;
|
||||
|
@ -387,7 +388,7 @@ final class HarbormasterBuild extends HarbormasterDAO
|
|||
public function isAborting() {
|
||||
$is_aborting = false;
|
||||
foreach ($this->getUnprocessedMessages() as $message_object) {
|
||||
$message_type = $message_object->getCommand();
|
||||
$message_type = $message_object->getType();
|
||||
switch ($message_type) {
|
||||
case HarbormasterBuildCommand::COMMAND_ABORT:
|
||||
$is_aborting = true;
|
||||
|
@ -399,9 +400,13 @@ final class HarbormasterBuild extends HarbormasterDAO
|
|||
}
|
||||
|
||||
public function markUnprocessedMessagesAsProcessed() {
|
||||
// TODO: See T13072. This is a placeholder until BuildCommand and
|
||||
// BuildMessage merge.
|
||||
return $this->deleteUnprocessedMessages();
|
||||
foreach ($this->getUnprocessedMessages() as $key => $message_object) {
|
||||
$message_object
|
||||
->setIsConsumed(1)
|
||||
->save();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function deleteUnprocessedMessages() {
|
||||
|
|
Loading…
Reference in a new issue