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

Provide a workflow to restart Harbormaster builds

Summary:
Ref T10867 for original use case. This workflow provides a plausible way for administrators to stop the daemons when performing upgrades or maintenance, then bring those daemons back up without resulting in the failure of builds that were running at the time.

On our organization's phab install, builds are running 24/7. The majority of these builds last for at least several minutes, and contain build steps which fail if interrupted and then resumed, as happens when turning daemons on and off.

Instead of allowing these build steps to resume execution as normal, this workflow will instruct active builds to restart their entire build process instead of just resuming whichever step they were on.

Test Plan:
contrived a build plan which would fail if resumed partway through:

- lease a working copy
- command `touch restart_{build.id}`
- command `test -e restart_{build.id} && rm restart_{build.id} && sleep 60`

followed old procedure:

- run a few of these builds manually
- `./bin/phd stop`
- `./bin/phd start`
- saw the builds fail

followed new procedure:

- run a few of these builds manually
- `./bin/phd stop`
- `./bin/harbormaster restart --active`
- `./bin/phd start`
- saw the builds pass

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Maniphest Tasks: T10867

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

+107
+2
src/__phutil_library_map__.php
··· 1190 1190 'HarbormasterLintPropertyView' => 'applications/harbormaster/view/HarbormasterLintPropertyView.php', 1191 1191 'HarbormasterManagementArchiveLogsWorkflow' => 'applications/harbormaster/management/HarbormasterManagementArchiveLogsWorkflow.php', 1192 1192 'HarbormasterManagementBuildWorkflow' => 'applications/harbormaster/management/HarbormasterManagementBuildWorkflow.php', 1193 + 'HarbormasterManagementRestartWorkflow' => 'applications/harbormaster/management/HarbormasterManagementRestartWorkflow.php', 1193 1194 'HarbormasterManagementUpdateWorkflow' => 'applications/harbormaster/management/HarbormasterManagementUpdateWorkflow.php', 1194 1195 'HarbormasterManagementWorkflow' => 'applications/harbormaster/management/HarbormasterManagementWorkflow.php', 1195 1196 'HarbormasterMessageType' => 'applications/harbormaster/engine/HarbormasterMessageType.php', ··· 5785 5786 'HarbormasterLintPropertyView' => 'AphrontView', 5786 5787 'HarbormasterManagementArchiveLogsWorkflow' => 'HarbormasterManagementWorkflow', 5787 5788 'HarbormasterManagementBuildWorkflow' => 'HarbormasterManagementWorkflow', 5789 + 'HarbormasterManagementRestartWorkflow' => 'HarbormasterManagementWorkflow', 5788 5790 'HarbormasterManagementUpdateWorkflow' => 'HarbormasterManagementWorkflow', 5789 5791 'HarbormasterManagementWorkflow' => 'PhabricatorManagementWorkflow', 5790 5792 'HarbormasterMessageType' => 'Phobject',
+100
src/applications/harbormaster/management/HarbormasterManagementRestartWorkflow.php
··· 1 + <?php 2 + 3 + final class HarbormasterManagementRestartWorkflow 4 + extends HarbormasterManagementWorkflow { 5 + 6 + protected function didConstruct() { 7 + $this 8 + ->setName('restart') 9 + ->setExamples( 10 + "**restart** --active\n". 11 + '**restart** --id id') 12 + ->setSynopsis(pht('Restart Harbormaster builds.')) 13 + ->setArguments( 14 + array( 15 + array( 16 + 'name' => 'id', 17 + 'param' => 'id', 18 + 'repeat' => true, 19 + 'help' => pht('Select one or more builds by ID.'), 20 + ), 21 + array( 22 + 'name' => 'active', 23 + 'help' => pht('Select all active builds.'), 24 + ), 25 + )); 26 + } 27 + 28 + public function execute(PhutilArgumentParser $args) { 29 + $viewer = $this->getViewer(); 30 + $ids = $args->getArg('id'); 31 + $active = $args->getArg('active'); 32 + 33 + if (!$ids && !$active) { 34 + throw new PhutilArgumentUsageException( 35 + pht('Use --id or --active to select builds.')); 36 + } if ($ids && $active) { 37 + throw new PhutilArgumentUsageException( 38 + pht('Use one of --id or --active to select builds, but not both.')); 39 + } 40 + 41 + $query = id(new HarbormasterBuildQuery()) 42 + ->setViewer($viewer); 43 + if ($ids) { 44 + $query->withIDs($ids); 45 + } else { 46 + $query->withBuildStatuses( 47 + HarbormasterBuildStatus::getActiveStatusConstants()); 48 + } 49 + $builds = $query->execute(); 50 + 51 + $console = PhutilConsole::getConsole(); 52 + $count = count($builds); 53 + if (!$count) { 54 + $console->writeOut("%s\n", pht('No builds to restart.')); 55 + return 0; 56 + } 57 + $prompt = pht('Restart %s build(s)?', new PhutilNumber($count)); 58 + if (!phutil_console_confirm($prompt)) { 59 + $console->writeOut("%s\n", pht('Cancelled.')); 60 + return 1; 61 + } 62 + 63 + $app_phid = id(new PhabricatorHarbormasterApplication())->getPHID(); 64 + $editor = id(new HarbormasterBuildTransactionEditor()) 65 + ->setActor($viewer) 66 + ->setActingAsPHID($app_phid) 67 + ->setContentSource($this->newContentSource()); 68 + foreach ($builds as $build) { 69 + $console->writeOut( 70 + "<bg:blue> %s </bg> %s\n", 71 + pht('RESTARTING'), 72 + pht('Build %d: %s', $build->getID(), $build->getName())); 73 + if (!$build->canRestartBuild()) { 74 + $console->writeOut( 75 + "<bg:yellow> %s </bg> %s\n", 76 + pht('INVALID'), 77 + pht('Cannot be restarted.')); 78 + continue; 79 + } 80 + $xactions = array(); 81 + $xactions[] = id(new HarbormasterBuildTransaction()) 82 + ->setTransactionType(HarbormasterBuildTransaction::TYPE_COMMAND) 83 + ->setNewValue(HarbormasterBuildCommand::COMMAND_RESTART); 84 + try { 85 + $editor->applyTransactions($build, $xactions); 86 + } catch (Exception $e) { 87 + $message = phutil_console_wrap($e->getMessage(), 2); 88 + $console->writeOut( 89 + "<bg:red> %s </bg>\n%s\n", 90 + pht('FAILED'), 91 + $message); 92 + continue; 93 + } 94 + $console->writeOut("<bg:green> %s </bg>\n", pht('SUCCESS')); 95 + } 96 + 97 + return 0; 98 + } 99 + 100 + }
+5
src/infrastructure/internationalization/translation/PhabricatorUSEnglishTranslation.php
··· 1573 1573 1574 1574 '%s updated the invite list for %s, invited %s: %s; uninvinted %s: %s.' => 1575 1575 '%s updated the invite list for %s, invited: %4$s; uninvited: %6$s.', 1576 + 1577 + 'Restart %s build(s)?' => array( 1578 + 'Restart %s build?', 1579 + 'Restart %s builds?', 1580 + ), 1576 1581 ); 1577 1582 } 1578 1583