2011-03-10 13:48:29 -08:00
|
|
|
<?php
|
|
|
|
|
2012-03-13 16:21:04 -07:00
|
|
|
final class PhabricatorTaskmasterDaemon extends PhabricatorDaemon {
|
2011-03-10 13:48:29 -08:00
|
|
|
|
|
|
|
public function run() {
|
|
|
|
$sleep = 0;
|
|
|
|
do {
|
2012-11-01 11:30:16 -07:00
|
|
|
$tasks = id(new PhabricatorWorkerLeaseQuery())
|
|
|
|
->setLimit(1)
|
|
|
|
->execute();
|
2011-03-10 13:48:29 -08:00
|
|
|
|
2012-11-01 11:30:16 -07:00
|
|
|
if ($tasks) {
|
2011-03-10 13:48:29 -08:00
|
|
|
foreach ($tasks as $task) {
|
2012-10-31 15:22:16 -07:00
|
|
|
$id = $task->getID();
|
|
|
|
$class = $task->getTaskClass();
|
|
|
|
|
|
|
|
$this->log("Working on task {$id} ({$class})...");
|
|
|
|
|
2012-11-01 11:30:23 -07:00
|
|
|
$task = $task->executeTask();
|
|
|
|
$ex = $task->getExecutionException();
|
|
|
|
if ($ex) {
|
2013-07-09 16:22:33 -07:00
|
|
|
if ($ex instanceof PhabricatorWorkerPermanentFailureException) {
|
|
|
|
$this->log("Task {$id} failed permanently.");
|
2014-04-16 13:02:12 -07:00
|
|
|
} else if ($ex instanceof PhabricatorWorkerYieldException) {
|
|
|
|
$this->log(pht('Task %s yielded.', $id));
|
2013-07-09 16:22:33 -07:00
|
|
|
} else {
|
|
|
|
$this->log("Task {$id} failed!");
|
2013-07-23 12:57:28 -07:00
|
|
|
throw new PhutilProxyException(
|
|
|
|
"Error while executing task ID {$id} from queue.",
|
|
|
|
$ex);
|
2013-07-09 16:22:33 -07:00
|
|
|
}
|
2012-11-01 11:30:23 -07:00
|
|
|
} else {
|
|
|
|
$this->log("Task {$id} complete! Moved to archive.");
|
2011-03-10 13:48:29 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$sleep = 0;
|
|
|
|
} else {
|
|
|
|
$sleep = min($sleep + 1, 30);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->sleep($sleep);
|
Send graceful shutdown signals to daemons in Phabricator
Summary:
Fixes T5855. Adds a `--graceful N` flag to `phd stop` and `phd restart`.
`phd` will send SIGINT, wait `N` seconds, SIGTERM, wait 15 seconds, and SIGKILL. By default, `N` is 15.
Test Plan:
- Ran `bin/phd debug ...` and used `^C` to interrupt daemons. Saw graceful shutdown behavior, and abrupt termination on multiple `^C`.
- Ran `bin/phd start`, `bin/phd stop` and `bin/phd restart` with `--graceful` set to various things, notably `0`. Saw graceful shutdowns on the CLI and in the web UI. With `0`, abrupt shutdowns.
Reviewers: btrahan, hach-que
Reviewed By: hach-que
Subscribers: epriestley
Maniphest Tasks: T5855
Differential Revision: https://secure.phabricator.com/D10228
2014-08-11 20:18:31 -07:00
|
|
|
} while (!$this->shouldExit());
|
2011-03-10 13:48:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|