1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 06:20:56 +01:00

Move Harbormaster log compression to the worker task queue

Summary: Depends on D19130. Ref T13088. Currently, when a build log is closed we compress it in the same process. Separate this out into a dedicated worker since the plan is to do a lot more work during finalization, none of which needs to happen inline during builds (or, particuarly, inline during a Conduit call for API writes in the future).

Test Plan: Ran `bin/harbormaster write-log --trace`, saw compression run inline.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13088

Differential Revision: https://secure.phabricator.com/D19131
This commit is contained in:
epriestley 2018-02-22 18:14:59 -08:00
parent cd4c4dc2ff
commit 32c6b649dd
4 changed files with 71 additions and 7 deletions

View file

@ -1306,6 +1306,7 @@ phutil_register_library_map(array(
'HarbormasterLeaseWorkingCopyBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterLeaseWorkingCopyBuildStepImplementation.php', 'HarbormasterLeaseWorkingCopyBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterLeaseWorkingCopyBuildStepImplementation.php',
'HarbormasterLintMessagesController' => 'applications/harbormaster/controller/HarbormasterLintMessagesController.php', 'HarbormasterLintMessagesController' => 'applications/harbormaster/controller/HarbormasterLintMessagesController.php',
'HarbormasterLintPropertyView' => 'applications/harbormaster/view/HarbormasterLintPropertyView.php', 'HarbormasterLintPropertyView' => 'applications/harbormaster/view/HarbormasterLintPropertyView.php',
'HarbormasterLogWorker' => 'applications/harbormaster/worker/HarbormasterLogWorker.php',
'HarbormasterManagementArchiveLogsWorkflow' => 'applications/harbormaster/management/HarbormasterManagementArchiveLogsWorkflow.php', 'HarbormasterManagementArchiveLogsWorkflow' => 'applications/harbormaster/management/HarbormasterManagementArchiveLogsWorkflow.php',
'HarbormasterManagementBuildWorkflow' => 'applications/harbormaster/management/HarbormasterManagementBuildWorkflow.php', 'HarbormasterManagementBuildWorkflow' => 'applications/harbormaster/management/HarbormasterManagementBuildWorkflow.php',
'HarbormasterManagementRestartWorkflow' => 'applications/harbormaster/management/HarbormasterManagementRestartWorkflow.php', 'HarbormasterManagementRestartWorkflow' => 'applications/harbormaster/management/HarbormasterManagementRestartWorkflow.php',
@ -6610,6 +6611,7 @@ phutil_register_library_map(array(
'HarbormasterLeaseWorkingCopyBuildStepImplementation' => 'HarbormasterBuildStepImplementation', 'HarbormasterLeaseWorkingCopyBuildStepImplementation' => 'HarbormasterBuildStepImplementation',
'HarbormasterLintMessagesController' => 'HarbormasterController', 'HarbormasterLintMessagesController' => 'HarbormasterController',
'HarbormasterLintPropertyView' => 'AphrontView', 'HarbormasterLintPropertyView' => 'AphrontView',
'HarbormasterLogWorker' => 'HarbormasterWorker',
'HarbormasterManagementArchiveLogsWorkflow' => 'HarbormasterManagementWorkflow', 'HarbormasterManagementArchiveLogsWorkflow' => 'HarbormasterManagementWorkflow',
'HarbormasterManagementBuildWorkflow' => 'HarbormasterManagementWorkflow', 'HarbormasterManagementBuildWorkflow' => 'HarbormasterManagementWorkflow',
'HarbormasterManagementRestartWorkflow' => 'HarbormasterManagementWorkflow', 'HarbormasterManagementRestartWorkflow' => 'HarbormasterManagementWorkflow',

View file

@ -39,7 +39,6 @@ final class HarbormasterManagementWriteLogWorkflow
$target_id)); $target_id));
} }
$log = HarbormasterBuildLog::initializeNewBuildLog($target); $log = HarbormasterBuildLog::initializeNewBuildLog($target);
$log->openBuildLog(); $log->openBuildLog();
@ -50,6 +49,12 @@ final class HarbormasterManagementWriteLogWorkflow
$content = file_get_contents('php://stdin'); $content = file_get_contents('php://stdin');
$log->append($content); $log->append($content);
echo tsprintf(
"%s\n",
pht('Write completed. Closing log...'));
PhabricatorWorker::setRunAllTasksInProcess(true);
$log->closeBuildLog(); $log->closeBuildLog();
echo tsprintf( echo tsprintf(

View file

@ -52,17 +52,24 @@ final class HarbormasterBuildLog
throw new Exception(pht('This build log is not open!')); throw new Exception(pht('This build log is not open!'));
} }
if ($this->canCompressLog()) {
$this->compressLog();
}
$start = $this->getDateCreated(); $start = $this->getDateCreated();
$now = PhabricatorTime::getNow(); $now = PhabricatorTime::getNow();
return $this $this
->setDuration($now - $start) ->setDuration($now - $start)
->setLive(0) ->setLive(0)
->save(); ->save();
PhabricatorWorker::scheduleTask(
'HarbormasterLogWorker',
array(
'logPHID' => $this->getPHID(),
),
array(
'objectPHID' => $this->getPHID(),
));
return $this;
} }
@ -201,7 +208,7 @@ final class HarbormasterBuildLog
return implode('', $full_text); return implode('', $full_text);
} }
private function canCompressLog() { public function canCompressLog() {
return function_exists('gzdeflate'); return function_exists('gzdeflate');
} }

View file

@ -0,0 +1,50 @@
<?php
final class HarbormasterLogWorker extends HarbormasterWorker {
protected function doWork() {
$viewer = $this->getViewer();
$data = $this->getTaskData();
$log_phid = idx($data, 'logPHID');
$log = id(new HarbormasterBuildLogQuery())
->setViewer($viewer)
->withPHIDs(array($log_phid))
->executeOne();
if (!$log) {
throw new PhabricatorWorkerPermanentFailureException(
pht('Invalid build log PHID "%s".', $log_phid));
}
$phid_key = PhabricatorHash::digestToLength($log_phid, 14);
$lock_key = "build.log({$phid_key})";
$lock = PhabricatorGlobalLock::newLock($lock_key);
try {
$lock->lock();
} catch (PhutilLockException $ex) {
throw new PhabricatorWorkerYieldException(15);
}
$caught = null;
try {
$this->finalizeBuildLog($log);
} catch (Exception $ex) {
$caught = $ex;
}
$lock->unlock();
if ($caught) {
throw $caught;
}
}
private function finalizeBuildLog(HarbormasterBuildLog $log) {
if ($log->canCompressLog()) {
$log->compressLog();
}
}
}