Changeset View
Changeset View
Standalone View
Standalone View
src/daemon/PhutilDaemonHandle.php
Show First 20 Lines • Show All 186 Lines • ▼ Show 20 Lines | private function updateHangDetection() { | ||||
if (time() > $this->deadline) { | if (time() > $this->deadline) { | ||||
$this->logMessage('HANG', pht('Hang detected. Restarting process.')); | $this->logMessage('HANG', pht('Hang detected. Restarting process.')); | ||||
$this->annihilateProcessGroup(); | $this->annihilateProcessGroup(); | ||||
$this->scheduleRestart(); | $this->scheduleRestart(); | ||||
} | } | ||||
} | } | ||||
private function scheduleRestart() { | private function scheduleRestart() { | ||||
$this->logMessage('WAIT', pht('Waiting to restart process.')); | // Wait a minimum of a few sceconds before restarting, but we may wait | ||||
$this->restartAt = time() + self::getWaitBeforeRestart(); | // longer if the daemon has initiated hibernation. | ||||
$default_restart = time() + self::getWaitBeforeRestart(); | |||||
if ($default_restart >= $this->restartAt) { | |||||
$this->restartAt = $default_restart; | |||||
} | |||||
$this->logMessage( | |||||
'WAIT', | |||||
pht( | |||||
'Waiting %s second(s) to restart process.', | |||||
new PhutilNumber($this->restartAt - time()))); | |||||
} | } | ||||
/** | /** | ||||
* Generate a unique ID for this daemon. | * Generate a unique ID for this daemon. | ||||
* | * | ||||
* @return string A unique daemon ID. | * @return string A unique daemon ID. | ||||
*/ | */ | ||||
private function generateDaemonID() { | private function generateDaemonID() { | ||||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | while (true) { | ||||
$this->busyEpoch = null; | $this->busyEpoch = null; | ||||
break; | break; | ||||
case PhutilDaemon::MESSAGETYPE_DOWN: | case PhutilDaemon::MESSAGETYPE_DOWN: | ||||
// The daemon is exiting because it doesn't have enough work and it | // The daemon is exiting because it doesn't have enough work and it | ||||
// is trying to scale the pool down. We should not restart it. | // is trying to scale the pool down. We should not restart it. | ||||
$this->shouldRestart = false; | $this->shouldRestart = false; | ||||
$this->shouldShutdown = true; | $this->shouldShutdown = true; | ||||
break; | break; | ||||
case PhutilDaemon::MESSAGETYPE_HIBERNATE: | |||||
$config = idx($structure, 1); | |||||
$duration = (int)idx($config, 'duration', 0); | |||||
$this->restartAt = time() + $duration; | |||||
$this->logMessage( | |||||
'ZZZZ', | |||||
pht( | |||||
'Process is preparing to hibernate for %s second(s).', | |||||
new PhutilNumber($duration))); | |||||
break; | |||||
default: | default: | ||||
// If we can't parse this or it isn't a message we understand, just | // If we can't parse this or it isn't a message we understand, just | ||||
// emit the raw message. | // emit the raw message. | ||||
$this->logMessage('STDO', pht('<Malformed> %s', $message)); | $this->logMessage('STDO', pht('<Malformed> %s', $message)); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 96 Lines • Show Last 20 Lines |