diff --git a/src/applications/daemon/query/PhabricatorDaemonLogQuery.php b/src/applications/daemon/query/PhabricatorDaemonLogQuery.php index bb00f9ff85..448c6f8927 100644 --- a/src/applications/daemon/query/PhabricatorDaemonLogQuery.php +++ b/src/applications/daemon/query/PhabricatorDaemonLogQuery.php @@ -1,132 +1,145 @@ ids = $ids; return $this; } public function withStatus($status) { $this->status = $status; return $this; } + public function withDaemonClasses(array $classes) { + $this->daemonClasses = $classes; + return $this; + } + public function loadPage() { $table = new PhabricatorDaemonLog(); $conn_r = $table->establishConnection('r'); $data = queryfx_all( $conn_r, 'SELECT * FROM %T %Q %Q %Q', $table->getTableName(), $this->buildWhereClause($conn_r), $this->buildOrderClause($conn_r), $this->buildLimitClause($conn_r)); return $table->loadAllFromArray($data); } public function willFilterPage(array $daemons) { $unknown_delay = PhabricatorDaemonLogQuery::getTimeUntilUnknown(); $dead_delay = PhabricatorDaemonLogQuery::getTimeUntilDead(); $status_running = PhabricatorDaemonLog::STATUS_RUNNING; $status_unknown = PhabricatorDaemonLog::STATUS_UNKNOWN; $status_wait = PhabricatorDaemonLog::STATUS_WAIT; $status_exited = PhabricatorDaemonLog::STATUS_EXITED; $status_dead = PhabricatorDaemonLog::STATUS_DEAD; $filter = array_fuse($this->getStatusConstants()); foreach ($daemons as $key => $daemon) { $status = $daemon->getStatus(); $seen = $daemon->getDateModified(); $is_running = ($status == $status_running) || ($status == $status_wait); // If we haven't seen the daemon recently, downgrade its status to // unknown. $unknown_time = ($seen + $unknown_delay); if ($is_running && ($unknown_time < time())) { $status = $status_unknown; } // If the daemon hasn't been seen in quite a while, assume it is dead. $dead_time = ($seen + $dead_delay); if (($status == $status_unknown) && ($dead_time < time())) { $status = $status_dead; } // If we changed the daemon's status, update it. if ($status != $daemon->getStatus()) { $guard = AphrontWriteGuard::beginScopedUnguardedWrites(); $daemon->setStatus($status)->save(); unset($guard); } // If the daemon no longer matches the filter, get rid of it. if ($filter) { if (empty($filter[$daemon->getStatus()])) { unset($daemons[$key]); } } } return $daemons; } private function buildWhereClause(AphrontDatabaseConnection $conn_r) { $where = array(); if ($this->ids) { $where[] = qsprintf( $conn_r, 'id IN (%Ld)', $this->ids); } if ($this->getStatusConstants()) { $where[] = qsprintf( $conn_r, 'status IN (%Ls)', $this->getStatusConstants()); } + if ($this->daemonClasses) { + $where[] = qsprintf( + $conn_r, + 'daemon IN (%Ls)', + $this->daemonClasses); + } + $where[] = $this->buildPagingClause($conn_r); return $this->formatWhereClause($where); } private function getStatusConstants() { $status = $this->status; switch ($status) { case self::STATUS_ALL: return array(); case self::STATUS_ALIVE: return array( PhabricatorDaemonLog::STATUS_UNKNOWN, PhabricatorDaemonLog::STATUS_RUNNING, PhabricatorDaemonLog::STATUS_WAIT, ); default: throw new Exception("Unknown status '{$status}'!"); } } } diff --git a/src/applications/repository/controller/PhabricatorRepositoryController.php b/src/applications/repository/controller/PhabricatorRepositoryController.php index 20b33dc924..ba5bfacc23 100644 --- a/src/applications/repository/controller/PhabricatorRepositoryController.php +++ b/src/applications/repository/controller/PhabricatorRepositoryController.php @@ -1,77 +1,66 @@ buildStandardPageView(); $page->setApplicationName('Repositories'); $page->setBaseURI('/repository/'); $page->setTitle(idx($data, 'title')); $page->setGlyph("rX"); $page->appendChild($view); $response = new AphrontWebpageResponse(); return $response->setContent($page->render()); } private function isPullDaemonRunning() { - // TODO: This is yuck, fix it. - $control = new PhabricatorDaemonManagementListWorkflow(); - $daemons = $control->loadRunningDaemons(); - foreach ($daemons as $daemon) { - if ($daemon->isRunning() && - $daemon->getName() == 'PhabricatorRepositoryPullLocalDaemon') - return true; - } - return false; + $daemons = id(new PhabricatorDaemonLogQuery()) + ->setViewer(PhabricatorUser::getOmnipotentUser()) + ->withStatus(PhabricatorDaemonLogQuery::STATUS_ALIVE) + ->withDaemonClasses(array('PhabricatorRepositoryPullLocalDaemon')) + ->setLimit(1) + ->execute(); + + return (bool)$daemons; } protected function renderDaemonNotice() { $documentation = phutil_tag( 'a', array( 'href' => PhabricatorEnv::getDoclink( 'article/Diffusion_User_Guide.html'), ), 'Diffusion User Guide'); $common = hsprintf( "Without this daemon, Phabricator will not be able to import or update ". "repositories. For instructions on starting the daemon, see %s.", phutil_tag('strong', array(), $documentation)); - try { - $daemon_running = $this->isPullDaemonRunning(); - if ($daemon_running) { - return null; - } - $title = "Repository Daemon Not Running"; - $message = hsprintf( - "
The repository daemon is not running on this machine. %s
", - $common); - } catch (Exception $ex) { - $title = "Unable To Verify Repository Daemon"; - $message = hsprintf( - "Unable to determine if the repository daemon is running on this ". - "machine. %s
". - "Exception: %s
", - $common, - $ex->getMessage()); + $daemon_running = $this->isPullDaemonRunning(); + if ($daemon_running) { + return null; } + $title = "Repository Daemon Not Running"; + $message = hsprintf( + "The repository daemon is not running. %s
", + $common); $view = new AphrontErrorView(); $view->setSeverity(AphrontErrorView::SEVERITY_WARNING); $view->setTitle($title); $view->appendChild($message); return $view; } }