Page MenuHomePhabricator

D21425.diff
No OneTemporary

D21425.diff

diff --git a/src/infrastructure/daemon/PhutilDaemonHandle.php b/src/infrastructure/daemon/PhutilDaemonHandle.php
--- a/src/infrastructure/daemon/PhutilDaemonHandle.php
+++ b/src/infrastructure/daemon/PhutilDaemonHandle.php
@@ -16,7 +16,6 @@
private $restartAt;
private $busyEpoch;
- private $pid;
private $daemonID;
private $deadline;
private $heartbeat;
@@ -104,7 +103,7 @@
}
public function isRunning() {
- return (bool)$this->future;
+ return (bool)$this->getFuture();
}
public function isHibernating() {
@@ -134,10 +133,6 @@
return (!$this->shouldRestart && !$this->isRunning());
}
- public function getFuture() {
- return $this->future;
- }
-
public function update() {
if (!$this->isRunning()) {
if (!$this->shouldRestart) {
@@ -152,11 +147,19 @@
$this->startDaemonProcess();
}
- $future = $this->future;
+ $future = $this->getFuture();
$result = null;
- if ($future->isReady()) {
- $result = $future->resolve();
+ $caught = null;
+ if ($future->canResolve()) {
+ $this->future = null;
+ try {
+ $result = $future->resolve();
+ } catch (Exception $ex) {
+ $caught = $ex;
+ } catch (Throwable $ex) {
+ $caught = $ex;
+ }
}
list($stdout, $stderr) = $future->read();
@@ -173,16 +176,22 @@
}
}
- if ($result !== null) {
- list($err) = $result;
+ if ($result !== null || $caught !== null) {
- if ($err) {
- $this->logMessage('FAIL', pht('Process exited with error %s.', $err));
+ if ($caught) {
+ $message = pht(
+ 'Process failed with exception: %s',
+ $caught->getMessage());
+ $this->logMessage('FAIL', $message);
} else {
- $this->logMessage('DONE', pht('Process exited normally.'));
- }
+ list($err) = $result;
- $this->future = null;
+ if ($err) {
+ $this->logMessage('FAIL', pht('Process exited with error %s.', $err));
+ } else {
+ $this->logMessage('DONE', pht('Process exited normally.'));
+ }
+ }
if ($this->shouldShutdown) {
$this->restartAt = null;
@@ -244,8 +253,22 @@
return $this->daemonID;
}
- public function getPID() {
- return $this->pid;
+ private function getFuture() {
+ return $this->future;
+ }
+
+ private function getPID() {
+ $future = $this->getFuture();
+
+ if (!$future) {
+ return null;
+ }
+
+ if (!$future->hasPID()) {
+ return null;
+ }
+
+ return $future->getPID();
}
private function getCaptureBufferSize() {
@@ -346,10 +369,12 @@
$this->stdoutBuffer = '';
$this->hibernating = false;
- $this->future = $this->newExecFuture();
- $this->future->start();
+ $future = $this->newExecFuture();
+ $this->future = $future;
- $this->pid = $this->future->getPID();
+ $pool = $this->getDaemonPool();
+ $overseer = $pool->getOverseer();
+ $overseer->addFutureToPool($future);
}
private function didReadStdout($data) {
diff --git a/src/infrastructure/daemon/PhutilDaemonOverseer.php b/src/infrastructure/daemon/PhutilDaemonOverseer.php
--- a/src/infrastructure/daemon/PhutilDaemonOverseer.php
+++ b/src/infrastructure/daemon/PhutilDaemonOverseer.php
@@ -181,10 +181,6 @@
}
}
- foreach ($pool->getFutures() as $future) {
- $future_pool->addFuture($future);
- }
-
if ($pool->getDaemons()) {
$running_pools = true;
}
@@ -210,6 +206,11 @@
exit($this->err);
}
+ public function addFutureToPool(Future $future) {
+ $this->getFuturePool()->addFuture($future);
+ return $this;
+ }
+
private function getFuturePool() {
if (!$this->futurePool) {
$pool = new FuturePool();
diff --git a/src/infrastructure/daemon/PhutilDaemonPool.php b/src/infrastructure/daemon/PhutilDaemonPool.php
--- a/src/infrastructure/daemon/PhutilDaemonPool.php
+++ b/src/infrastructure/daemon/PhutilDaemonPool.php
@@ -111,18 +111,6 @@
return $this->daemons;
}
- public function getFutures() {
- $futures = array();
- foreach ($this->getDaemons() as $daemon) {
- $future = $daemon->getFuture();
- if ($future) {
- $futures[] = $future;
- }
- }
-
- return $futures;
- }
-
public function didReceiveSignal($signal, $signo) {
switch ($signal) {
case PhutilDaemonOverseer::SIGNAL_GRACEFUL:

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 25, 9:22 AM (4 h, 7 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6785550
Default Alt Text
D21425.diff (4 KB)

Event Timeline