Replace "Cancel Build" with "Stop", "Resume" and "Restart"
Summary:
Ref T1049. Currently you can cancel a build, but now that we're tracking a lot more state we can stop, resume, and restart builds.
When the user issues a command against a build, I'm writing it into an auxiliary queue (`HarbormasterBuildCommand`) and then reading them out in the worker. This is mostly to avoid race messes where we try to `save()` the object in multiple places: basically, the BuildEngine is the //only// thing that writes to Build objects, and it holds a lock while it does it.
Test Plan:
- Created a plan which runs "sleep 2" a bunch of times in a row.
- Stopped, resumed, and restarted it.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran, chad
Maniphest Tasks: T1049
Differential Revision: https://secure.phabricator.com/D7892
2014-01-06 12:32:20 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class HarbormasterBuildActionController
|
|
|
|
extends HarbormasterController {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
private $action;
|
2014-01-06 14:12:05 -08:00
|
|
|
private $via;
|
Replace "Cancel Build" with "Stop", "Resume" and "Restart"
Summary:
Ref T1049. Currently you can cancel a build, but now that we're tracking a lot more state we can stop, resume, and restart builds.
When the user issues a command against a build, I'm writing it into an auxiliary queue (`HarbormasterBuildCommand`) and then reading them out in the worker. This is mostly to avoid race messes where we try to `save()` the object in multiple places: basically, the BuildEngine is the //only// thing that writes to Build objects, and it holds a lock while it does it.
Test Plan:
- Created a plan which runs "sleep 2" a bunch of times in a row.
- Stopped, resumed, and restarted it.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran, chad
Maniphest Tasks: T1049
Differential Revision: https://secure.phabricator.com/D7892
2014-01-06 12:32:20 -08:00
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
$this->action = $data['action'];
|
2014-01-06 14:12:05 -08:00
|
|
|
$this->via = idx($data, 'via');
|
Replace "Cancel Build" with "Stop", "Resume" and "Restart"
Summary:
Ref T1049. Currently you can cancel a build, but now that we're tracking a lot more state we can stop, resume, and restart builds.
When the user issues a command against a build, I'm writing it into an auxiliary queue (`HarbormasterBuildCommand`) and then reading them out in the worker. This is mostly to avoid race messes where we try to `save()` the object in multiple places: basically, the BuildEngine is the //only// thing that writes to Build objects, and it holds a lock while it does it.
Test Plan:
- Created a plan which runs "sleep 2" a bunch of times in a row.
- Stopped, resumed, and restarted it.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran, chad
Maniphest Tasks: T1049
Differential Revision: https://secure.phabricator.com/D7892
2014-01-06 12:32:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
$command = $this->action;
|
|
|
|
|
|
|
|
$build = id(new HarbormasterBuildQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->executeOne();
|
|
|
|
if (!$build) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($command) {
|
|
|
|
case HarbormasterBuildCommand::COMMAND_RESTART:
|
|
|
|
$can_issue = $build->canRestartBuild();
|
|
|
|
break;
|
|
|
|
case HarbormasterBuildCommand::COMMAND_STOP:
|
|
|
|
$can_issue = $build->canStopBuild();
|
|
|
|
break;
|
|
|
|
case HarbormasterBuildCommand::COMMAND_RESUME:
|
|
|
|
$can_issue = $build->canResumeBuild();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return new Aphront400Response();
|
|
|
|
}
|
|
|
|
|
2014-01-06 14:12:05 -08:00
|
|
|
switch ($this->via) {
|
|
|
|
case 'buildable':
|
|
|
|
$return_uri = $build->getBuildable()->getMonogram();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$return_uri = $this->getApplicationURI('/build/'.$build->getID().'/');
|
|
|
|
break;
|
|
|
|
}
|
Replace "Cancel Build" with "Stop", "Resume" and "Restart"
Summary:
Ref T1049. Currently you can cancel a build, but now that we're tracking a lot more state we can stop, resume, and restart builds.
When the user issues a command against a build, I'm writing it into an auxiliary queue (`HarbormasterBuildCommand`) and then reading them out in the worker. This is mostly to avoid race messes where we try to `save()` the object in multiple places: basically, the BuildEngine is the //only// thing that writes to Build objects, and it holds a lock while it does it.
Test Plan:
- Created a plan which runs "sleep 2" a bunch of times in a row.
- Stopped, resumed, and restarted it.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran, chad
Maniphest Tasks: T1049
Differential Revision: https://secure.phabricator.com/D7892
2014-01-06 12:32:20 -08:00
|
|
|
|
|
|
|
if ($request->isDialogFormPost() && $can_issue) {
|
|
|
|
|
|
|
|
// Issue the new build command.
|
|
|
|
id(new HarbormasterBuildCommand())
|
|
|
|
->setAuthorPHID($viewer->getPHID())
|
|
|
|
->setTargetPHID($build->getPHID())
|
|
|
|
->setCommand($command)
|
|
|
|
->save();
|
|
|
|
|
|
|
|
// Schedule a build update. We may already have stuff in queue (in which
|
|
|
|
// case this will just no-op), but we might also be dealing with a
|
|
|
|
// stopped build, which won't restart unless we deal with this.
|
|
|
|
PhabricatorWorker::scheduleTask(
|
|
|
|
'HarbormasterBuildWorker',
|
|
|
|
array(
|
|
|
|
'buildID' => $build->getID()
|
|
|
|
));
|
|
|
|
|
2014-01-06 14:12:05 -08:00
|
|
|
return id(new AphrontRedirectResponse())->setURI($return_uri);
|
Replace "Cancel Build" with "Stop", "Resume" and "Restart"
Summary:
Ref T1049. Currently you can cancel a build, but now that we're tracking a lot more state we can stop, resume, and restart builds.
When the user issues a command against a build, I'm writing it into an auxiliary queue (`HarbormasterBuildCommand`) and then reading them out in the worker. This is mostly to avoid race messes where we try to `save()` the object in multiple places: basically, the BuildEngine is the //only// thing that writes to Build objects, and it holds a lock while it does it.
Test Plan:
- Created a plan which runs "sleep 2" a bunch of times in a row.
- Stopped, resumed, and restarted it.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran, chad
Maniphest Tasks: T1049
Differential Revision: https://secure.phabricator.com/D7892
2014-01-06 12:32:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch ($command) {
|
|
|
|
case HarbormasterBuildCommand::COMMAND_RESTART:
|
|
|
|
if ($can_issue) {
|
|
|
|
$title = pht('Really restart build?');
|
|
|
|
$body = pht(
|
|
|
|
'Progress on this build will be discarded and the build will '.
|
|
|
|
'restart. Side effects of the build will occur again. Really '.
|
|
|
|
'restart build?');
|
|
|
|
$submit = pht('Restart Build');
|
|
|
|
} else {
|
|
|
|
$title = pht('Unable to Restart Build');
|
|
|
|
if ($build->isRestarting()) {
|
|
|
|
$body = pht(
|
|
|
|
'This build is already restarting. You can not reissue a '.
|
|
|
|
'restart command to a restarting build.');
|
|
|
|
} else {
|
|
|
|
$body = pht(
|
|
|
|
'You can not restart this build.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case HarbormasterBuildCommand::COMMAND_STOP:
|
|
|
|
if ($can_issue) {
|
|
|
|
$title = pht('Really stop build?');
|
|
|
|
$body = pht(
|
|
|
|
'If you stop this build, work will halt once the current steps '.
|
|
|
|
'complete. You can resume the build later.');
|
|
|
|
$submit = pht('Stop Build');
|
|
|
|
} else {
|
|
|
|
$title = pht('Unable to Stop Build');
|
|
|
|
if ($build->isComplete()) {
|
|
|
|
$body = pht(
|
|
|
|
'This build is already complete. You can not stop a completed '.
|
|
|
|
'build.');
|
|
|
|
} else if ($build->isStopped()) {
|
|
|
|
$body = pht(
|
|
|
|
'This build is already stopped. You can not stop a build which '.
|
|
|
|
'has already been stopped.');
|
|
|
|
} else if ($build->isStopping()) {
|
|
|
|
$body = pht(
|
|
|
|
'This build is already stopping. You can not reissue a stop '.
|
|
|
|
'command to a stopping build.');
|
|
|
|
} else {
|
|
|
|
$body = pht(
|
|
|
|
'This build can not be stopped.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case HarbormasterBuildCommand::COMMAND_RESUME:
|
|
|
|
if ($can_issue) {
|
|
|
|
$title = pht('Really resume build?');
|
|
|
|
$body = pht(
|
|
|
|
'Work will continue on the build. Really resume?');
|
|
|
|
$submit = pht('Resume Build');
|
|
|
|
} else {
|
|
|
|
$title = pht('Unable to Resume Build');
|
|
|
|
if ($build->isResuming()) {
|
|
|
|
$body = pht(
|
|
|
|
'This build is already resuming. You can not reissue a resume '.
|
|
|
|
'command to a resuming build.');
|
|
|
|
} else if (!$build->isStopped()) {
|
|
|
|
$body = pht(
|
|
|
|
'This build is not stopped. You can only resume a stopped '.
|
|
|
|
'build.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setTitle($title)
|
|
|
|
->appendChild($body)
|
2014-01-06 14:12:05 -08:00
|
|
|
->addCancelButton($return_uri);
|
Replace "Cancel Build" with "Stop", "Resume" and "Restart"
Summary:
Ref T1049. Currently you can cancel a build, but now that we're tracking a lot more state we can stop, resume, and restart builds.
When the user issues a command against a build, I'm writing it into an auxiliary queue (`HarbormasterBuildCommand`) and then reading them out in the worker. This is mostly to avoid race messes where we try to `save()` the object in multiple places: basically, the BuildEngine is the //only// thing that writes to Build objects, and it holds a lock while it does it.
Test Plan:
- Created a plan which runs "sleep 2" a bunch of times in a row.
- Stopped, resumed, and restarted it.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran, chad
Maniphest Tasks: T1049
Differential Revision: https://secure.phabricator.com/D7892
2014-01-06 12:32:20 -08:00
|
|
|
|
|
|
|
if ($can_issue) {
|
|
|
|
$dialog->addSubmitButton($submit);
|
|
|
|
}
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|