Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/infrastructure/daemon/workers/query/PhabricatorWorkerArchiveTaskQuery.php b/src/infrastructure/daemon/workers/query/PhabricatorWorkerArchiveTaskQuery.php
index 69abac27b0..adc0992473 100644
--- a/src/infrastructure/daemon/workers/query/PhabricatorWorkerArchiveTaskQuery.php
+++ b/src/infrastructure/daemon/workers/query/PhabricatorWorkerArchiveTaskQuery.php
@@ -1,120 +1,122 @@
<?php
final class PhabricatorWorkerArchiveTaskQuery
extends PhabricatorQuery {
private $ids;
private $dateModifiedSince;
private $dateCreatedBefore;
private $objectPHIDs;
private $classNames;
private $limit;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withDateModifiedSince($timestamp) {
$this->dateModifiedSince = $timestamp;
return $this;
}
public function withDateCreatedBefore($timestamp) {
$this->dateCreatedBefore = $timestamp;
return $this;
}
public function withObjectPHIDs(array $phids) {
$this->objectPHIDs = $phids;
return $this;
}
public function withClassNames(array $names) {
$this->classNames = $names;
return $this;
}
public function setLimit($limit) {
$this->limit = $limit;
return $this;
}
public function execute() {
$task_table = new PhabricatorWorkerArchiveTask();
$conn_r = $task_table->establishConnection('r');
$rows = queryfx_all(
$conn_r,
'SELECT * FROM %T %Q %Q %Q',
$task_table->getTableName(),
$this->buildWhereClause($conn_r),
$this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r));
return $task_table->loadAllFromArray($rows);
}
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array();
if ($this->ids !== null) {
$where[] = qsprintf(
$conn_r,
'id in (%Ld)',
$this->ids);
}
if ($this->objectPHIDs !== null) {
$where[] = qsprintf(
$conn_r,
'objectPHID IN (%Ls)',
$this->objectPHIDs);
}
if ($this->dateModifiedSince !== null) {
$where[] = qsprintf(
$conn_r,
'dateModified > %d',
$this->dateModifiedSince);
}
if ($this->dateCreatedBefore !== null) {
$where[] = qsprintf(
$conn_r,
'dateCreated < %d',
$this->dateCreatedBefore);
}
if ($this->classNames !== null) {
$where[] = qsprintf(
$conn_r,
'taskClass IN (%Ls)',
$this->classNames);
}
return $this->formatWhereClause($where);
}
private function buildOrderClause(AphrontDatabaseConnection $conn_r) {
// NOTE: The garbage collector executes this query with a date constraint,
// and the query is inefficient if we don't use the same key for ordering.
// See T9808 for discussion.
if ($this->dateCreatedBefore) {
return qsprintf($conn_r, 'ORDER BY dateCreated DESC, id DESC');
+ } else if ($this->dateModifiedSince) {
+ return qsprintf($conn_r, 'ORDER BY dateModified DESC, id DESC');
} else {
return qsprintf($conn_r, 'ORDER BY id DESC');
}
}
private function buildLimitClause(AphrontDatabaseConnection $conn_r) {
$clause = '';
if ($this->limit) {
$clause = qsprintf($conn_r, 'LIMIT %d', $this->limit);
}
return $clause;
}
}
diff --git a/src/infrastructure/daemon/workers/storage/PhabricatorWorkerArchiveTask.php b/src/infrastructure/daemon/workers/storage/PhabricatorWorkerArchiveTask.php
index 9797373eb7..fe1164e532 100644
--- a/src/infrastructure/daemon/workers/storage/PhabricatorWorkerArchiveTask.php
+++ b/src/infrastructure/daemon/workers/storage/PhabricatorWorkerArchiveTask.php
@@ -1,97 +1,100 @@
<?php
final class PhabricatorWorkerArchiveTask extends PhabricatorWorkerTask {
const RESULT_SUCCESS = 0;
const RESULT_FAILURE = 1;
const RESULT_CANCELLED = 2;
protected $duration;
protected $result;
protected function getConfiguration() {
$parent = parent::getConfiguration();
$config = array(
// We manage the IDs in this table; they are allocated in the ActiveTask
// table and moved here without alteration.
self::CONFIG_IDS => self::IDS_MANUAL,
) + $parent;
$config[self::CONFIG_COLUMN_SCHEMA] = array(
'result' => 'uint32',
'duration' => 'uint64',
) + $config[self::CONFIG_COLUMN_SCHEMA];
$config[self::CONFIG_KEY_SCHEMA] = array(
'dateCreated' => array(
'columns' => array('dateCreated'),
),
'leaseOwner' => array(
'columns' => array('leaseOwner', 'priority', 'id'),
),
+ 'key_modified' => array(
+ 'columns' => array('dateModified'),
+ ),
) + $parent[self::CONFIG_KEY_SCHEMA];
return $config;
}
public function save() {
if ($this->getID() === null) {
throw new Exception(pht('Trying to archive a task with no ID.'));
}
$other = new PhabricatorWorkerActiveTask();
$conn_w = $this->establishConnection('w');
$this->openTransaction();
queryfx(
$conn_w,
'DELETE FROM %T WHERE id = %d',
$other->getTableName(),
$this->getID());
$result = parent::insert();
$this->saveTransaction();
return $result;
}
public function delete() {
$this->openTransaction();
if ($this->getDataID()) {
$conn_w = $this->establishConnection('w');
$data_table = new PhabricatorWorkerTaskData();
queryfx(
$conn_w,
'DELETE FROM %T WHERE id = %d',
$data_table->getTableName(),
$this->getDataID());
}
$result = parent::delete();
$this->saveTransaction();
return $result;
}
public function unarchiveTask() {
$this->openTransaction();
$active = id(new PhabricatorWorkerActiveTask())
->setID($this->getID())
->setTaskClass($this->getTaskClass())
->setLeaseOwner(null)
->setLeaseExpires(0)
->setFailureCount(0)
->setDataID($this->getDataID())
->setPriority($this->getPriority())
->setObjectPHID($this->getObjectPHID())
->insert();
$this->setDataID(null);
$this->delete();
$this->saveTransaction();
return $active;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Tue, Jun 10, 10:16 PM (1 d, 4 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
141182
Default Alt Text
(6 KB)

Event Timeline