1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 16:52:41 +01:00

Add a "--rate" flag to bin/harbormaster write-log to support testing live log streaming

Summary: Depends on D19151. Ref T13088. While dramatically less exciting than using `lolcat` and less general than `pv`, this should do the job adequately.

Test Plan: Piped a sizable log into `bin/harbormaster write-log` with `--rate 2048`, saw a progress bar. Loaded the log in the web UI and saw it grow as the page reloaded.

Reviewers: yelirekim

Reviewed By: yelirekim

Subscribers: yelirekim, PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13088

Differential Revision: https://secure.phabricator.com/D19152
This commit is contained in:
epriestley 2018-02-28 07:43:14 -08:00
parent 5a2213ef82
commit 21ddfe442e
2 changed files with 39 additions and 2 deletions

View file

@ -18,6 +18,13 @@ final class HarbormasterManagementWriteLogWorkflow
'param' => 'id',
'help' => pht('Build Target ID to attach the log to.'),
),
array(
'name' => 'rate',
'param' => 'bytes',
'help' => pht(
'Limit the rate at which the log is written, to test '.
'live log streaming.'),
),
));
}
@ -54,7 +61,37 @@ final class HarbormasterManagementWriteLogWorkflow
pht('Reading log content from stdin...'));
$content = file_get_contents('php://stdin');
$rate = $args->getArg('rate');
if ($rate) {
if ($rate <= 0) {
throw new Exception(
pht(
'Write rate must be more than 0 bytes/sec.'));
}
echo tsprintf(
"%s\n",
pht('Writing log, slowly...'));
$offset = 0;
$total = strlen($content);
$pieces = str_split($content, $rate);
$bar = id(new PhutilConsoleProgressBar())
->setTotal($total);
foreach ($pieces as $piece) {
$log->append($piece);
$bar->update(strlen($piece));
sleep(1);
}
$bar->done();
} else {
$log->append($content);
}
echo tsprintf(
"%s\n",

View file

@ -492,7 +492,7 @@ final class HarbormasterBuildLog
'UPDATE %T SET
chunk = CONCAT(chunk, %B),
size = %d,
tailOffset = headOffset + %d,
tailOffset = headOffset + %d
WHERE
id = %d',
$chunk_table,