From 21ddfe442e67bf1efebb142ec6d429b748c00c28 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 28 Feb 2018 07:43:14 -0800 Subject: [PATCH] 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 --- ...HarbormasterManagementWriteLogWorkflow.php | 39 ++++++++++++++++++- .../storage/build/HarbormasterBuildLog.php | 2 +- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/applications/harbormaster/management/HarbormasterManagementWriteLogWorkflow.php b/src/applications/harbormaster/management/HarbormasterManagementWriteLogWorkflow.php index b680b382aa..3676b1415c 100644 --- a/src/applications/harbormaster/management/HarbormasterManagementWriteLogWorkflow.php +++ b/src/applications/harbormaster/management/HarbormasterManagementWriteLogWorkflow.php @@ -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'); - $log->append($content); + + $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", diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuildLog.php b/src/applications/harbormaster/storage/build/HarbormasterBuildLog.php index 9d77abf4a8..bf69457254 100644 --- a/src/applications/harbormaster/storage/build/HarbormasterBuildLog.php +++ b/src/applications/harbormaster/storage/build/HarbormasterBuildLog.php @@ -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,