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

at recaptime-dev/main 115 lines 2.8 kB view raw
1<?php 2 3final class HarbormasterManagementWriteLogWorkflow 4 extends HarbormasterManagementWorkflow { 5 6 protected function didConstruct() { 7 $this 8 ->setName('write-log') 9 ->setExamples('**write-log** --target __id__ [__options__]') 10 ->setSynopsis( 11 pht( 12 'Write a new Harbormaster build log. This is primarily intended '. 13 'to make development and testing easier.')) 14 ->setArguments( 15 array( 16 array( 17 'name' => 'target', 18 'param' => 'id', 19 'help' => pht('Build Target ID to attach the log to.'), 20 ), 21 array( 22 'name' => 'rate', 23 'param' => 'bytes', 24 'help' => pht( 25 'Limit the rate at which the log is written, to test '. 26 'live log streaming.'), 27 ), 28 )); 29 } 30 31 public function execute(PhutilArgumentParser $args) { 32 $viewer = $this->getViewer(); 33 34 $target_id = $args->getArg('target'); 35 if (!$target_id) { 36 throw new PhutilArgumentUsageException( 37 pht('Choose a build target to attach the log to with "--target".')); 38 } 39 40 $target = id(new HarbormasterBuildTargetQuery()) 41 ->setViewer($viewer) 42 ->withIDs(array($target_id)) 43 ->executeOne(); 44 if (!$target) { 45 throw new PhutilArgumentUsageException( 46 pht( 47 'Unable to load build target "%s".', 48 $target_id)); 49 } 50 51 $log = HarbormasterBuildLog::initializeNewBuildLog($target); 52 $log->openBuildLog(); 53 54 echo tsprintf( 55 "%s\n\n __%s__\n\n", 56 pht('Opened a new build log:'), 57 PhabricatorEnv::getURI($log->getURI())); 58 59 echo tsprintf( 60 "%s\n", 61 pht('Reading log content from stdin...')); 62 63 $content = file_get_contents('php://stdin'); 64 65 $rate = $args->getArg('rate'); 66 if ($rate) { 67 if ($rate <= 0) { 68 throw new Exception( 69 pht( 70 'Write rate must be more than 0 bytes/sec.')); 71 } 72 73 echo tsprintf( 74 "%s\n", 75 pht('Writing log, slowly...')); 76 77 $offset = 0; 78 $total = 0; 79 $pieces = array(); 80 if ($content) { 81 $total = strlen($content); 82 $pieces = str_split($content, $rate); 83 } 84 85 $bar = id(new PhutilConsoleProgressBar()) 86 ->setTotal($total); 87 88 foreach ($pieces as $piece) { 89 $log->append($piece); 90 $bar->update(strlen($piece)); 91 sleep(1); 92 } 93 94 $bar->done(); 95 96 } else { 97 $log->append($content); 98 } 99 100 echo tsprintf( 101 "%s\n", 102 pht('Write completed. Closing log...')); 103 104 PhabricatorWorker::setRunAllTasksInProcess(true); 105 106 $log->closeBuildLog(); 107 108 echo tsprintf( 109 "%s\n", 110 pht('Done.')); 111 112 return 0; 113 } 114 115}