Changeset View
Changeset View
Standalone View
Standalone View
src/applications/daemon/query/PhabricatorDaemonLogQuery.php
<?php | <?php | ||||
final class PhabricatorDaemonLogQuery | final class PhabricatorDaemonLogQuery | ||||
extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
const STATUS_ALL = 'status-all'; | const STATUS_ALL = 'status-all'; | ||||
const STATUS_ALIVE = 'status-alive'; | const STATUS_ALIVE = 'status-alive'; | ||||
private $ids; | private $ids; | ||||
private $notIDs; | private $notIDs; | ||||
private $status = self::STATUS_ALL; | private $status = self::STATUS_ALL; | ||||
private $daemonClasses; | private $daemonClasses; | ||||
private $allowStatusWrites; | private $allowStatusWrites; | ||||
private $daemonIDs; | |||||
public static function getTimeUntilUnknown() { | public static function getTimeUntilUnknown() { | ||||
return 3 * PhutilDaemonHandle::getHeartbeatEventFrequency(); | return 3 * PhutilDaemonHandle::getHeartbeatEventFrequency(); | ||||
} | } | ||||
public static function getTimeUntilDead() { | public static function getTimeUntilDead() { | ||||
return 30 * PhutilDaemonHandle::getHeartbeatEventFrequency(); | return 30 * PhutilDaemonHandle::getHeartbeatEventFrequency(); | ||||
} | } | ||||
Show All 18 Lines | public function withDaemonClasses(array $classes) { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setAllowStatusWrites($allow) { | public function setAllowStatusWrites($allow) { | ||||
$this->allowStatusWrites = $allow; | $this->allowStatusWrites = $allow; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withDaemonIDs(array $daemon_ids) { | |||||
$this->daemonIDs = $daemon_ids; | |||||
return $this; | |||||
} | |||||
protected function loadPage() { | protected function loadPage() { | ||||
$table = new PhabricatorDaemonLog(); | $table = new PhabricatorDaemonLog(); | ||||
$conn_r = $table->establishConnection('r'); | $conn_r = $table->establishConnection('r'); | ||||
$data = queryfx_all( | $data = queryfx_all( | ||||
$conn_r, | $conn_r, | ||||
'SELECT * FROM %T %Q %Q %Q', | 'SELECT * FROM %T %Q %Q %Q', | ||||
$table->getTableName(), | $table->getTableName(), | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | protected function willFilterPage(array $daemons) { | ||||
} | } | ||||
return $daemons; | return $daemons; | ||||
} | } | ||||
private function buildWhereClause(AphrontDatabaseConnection $conn_r) { | private function buildWhereClause(AphrontDatabaseConnection $conn_r) { | ||||
$where = array(); | $where = array(); | ||||
if ($this->ids) { | if ($this->ids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn_r, | ||||
'id IN (%Ld)', | 'id IN (%Ld)', | ||||
$this->ids); | $this->ids); | ||||
} | } | ||||
if ($this->notIDs) { | if ($this->notIDs !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn_r, | ||||
'id NOT IN (%Ld)', | 'id NOT IN (%Ld)', | ||||
$this->notIDs); | $this->notIDs); | ||||
} | } | ||||
if ($this->getStatusConstants()) { | if ($this->getStatusConstants()) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn_r, | ||||
'status IN (%Ls)', | 'status IN (%Ls)', | ||||
$this->getStatusConstants()); | $this->getStatusConstants()); | ||||
} | } | ||||
if ($this->daemonClasses) { | if ($this->daemonClasses !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn_r, | ||||
'daemon IN (%Ls)', | 'daemon IN (%Ls)', | ||||
$this->daemonClasses); | $this->daemonClasses); | ||||
} | } | ||||
if ($this->daemonIDs !== null) { | |||||
$where[] = qsprintf( | |||||
$conn_r, | |||||
'daemonID IN (%Ls)', | |||||
$this->daemonIDs); | |||||
} | |||||
$where[] = $this->buildPagingClause($conn_r); | $where[] = $this->buildPagingClause($conn_r); | ||||
return $this->formatWhereClause($where); | return $this->formatWhereClause($where); | ||||
} | } | ||||
private function getStatusConstants() { | private function getStatusConstants() { | ||||
$status = $this->status; | $status = $this->status; | ||||
switch ($status) { | switch ($status) { | ||||
case self::STATUS_ALL: | case self::STATUS_ALL: | ||||
return array(); | return array(); | ||||
case self::STATUS_ALIVE: | case self::STATUS_ALIVE: | ||||
return array( | return array( | ||||
PhabricatorDaemonLog::STATUS_UNKNOWN, | PhabricatorDaemonLog::STATUS_UNKNOWN, | ||||
PhabricatorDaemonLog::STATUS_RUNNING, | PhabricatorDaemonLog::STATUS_RUNNING, | ||||
PhabricatorDaemonLog::STATUS_WAIT, | PhabricatorDaemonLog::STATUS_WAIT, | ||||
PhabricatorDaemonLog::STATUS_EXITING, | PhabricatorDaemonLog::STATUS_EXITING, | ||||
); | ); | ||||
default: | default: | ||||
throw new Exception("Unknown status '{$status}'!"); | throw new Exception(pht('Unknown status "%s"!', $status)); | ||||
} | } | ||||
} | } | ||||
public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
return 'PhabricatorDaemonsApplication'; | return 'PhabricatorDaemonsApplication'; | ||||
} | } | ||||
} | } |