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); }
public function collectGarbage() { $key = 'gcdaemon.ttl.task-archive'; $ttl = PhabricatorEnv::getEnvConfig($key); if ($ttl <= 0) { return false; } $table = new PhabricatorWorkerArchiveTask(); $data_table = new PhabricatorWorkerTaskData(); $conn_w = $table->establishConnection('w'); $rows = queryfx_all($conn_w, 'SELECT id, dataID FROM %T WHERE dateCreated < %d LIMIT 100', $table->getTableName(), time() - $ttl); if (!$rows) { return false; } $data_ids = array_filter(ipull($rows, 'dataID')); $task_ids = ipull($rows, 'id'); $table->openTransaction(); if ($data_ids) { queryfx($conn_w, 'DELETE FROM %T WHERE id IN (%Ld)', $data_table->getTableName(), $data_ids); } queryfx($conn_w, 'DELETE FROM %T WHERE id IN (%Ld)', $table->getTableName(), $task_ids); $table->saveTransaction(); return count($task_ids) == 100; }
protected function collectGarbage() { $table = new PhabricatorWorkerArchiveTask(); $data_table = new PhabricatorWorkerTaskData(); $conn_w = $table->establishConnection('w'); $tasks = id(new PhabricatorWorkerArchiveTaskQuery())->withDateCreatedBefore($this->getGarbageEpoch())->setLimit(100)->execute(); if (!$tasks) { return false; } $data_ids = array_filter(mpull($tasks, 'getDataID')); $task_ids = mpull($tasks, 'getID'); $table->openTransaction(); if ($data_ids) { queryfx($conn_w, 'DELETE FROM %T WHERE id IN (%Ld)', $data_table->getTableName(), $data_ids); } queryfx($conn_w, 'DELETE FROM %T WHERE id IN (%Ld)', $table->getTableName(), $task_ids); $table->saveTransaction(); return count($task_ids) == 100; }
public function collectGarbage() { $key = 'gcdaemon.ttl.task-archive'; $ttl = PhabricatorEnv::getEnvConfig($key); if ($ttl <= 0) { return false; } $table = new PhabricatorWorkerArchiveTask(); $data_table = new PhabricatorWorkerTaskData(); $conn_w = $table->establishConnection('w'); $tasks = id(new PhabricatorWorkerArchiveTaskQuery())->withDateCreatedBefore(time() - $ttl)->execute(); if (!$tasks) { return false; } $data_ids = array_filter(mpull($tasks, 'getDataID')); $task_ids = mpull($tasks, 'getID'); $table->openTransaction(); if ($data_ids) { queryfx($conn_w, 'DELETE FROM %T WHERE id IN (%Ld)', $data_table->getTableName(), $data_ids); } queryfx($conn_w, 'DELETE FROM %T WHERE id IN (%Ld)', $table->getTableName(), $task_ids); $table->saveTransaction(); return count($task_ids) == 100; }
<?php // Switch PhabricatorWorkerActiveTask from auto-increment IDs to counter IDs. // Set the initial counter ID to be larger than any known task ID. $active_table = new PhabricatorWorkerActiveTask(); $archive_table = new PhabricatorWorkerArchiveTask(); $old_table = 'worker_task'; $conn_w = $active_table->establishConnection('w'); $active_auto = head(queryfx_one($conn_w, 'SELECT auto_increment FROM information_schema.tables WHERE table_name = %s AND table_schema = DATABASE()', $old_table)); $active_max = head(queryfx_one($conn_w, 'SELECT MAX(id) FROM %T', $old_table)); $archive_max = head(queryfx_one($conn_w, 'SELECT MAX(id) FROM %T', $archive_table->getTableName())); $initial_counter = max((int) $active_auto, (int) $active_max, (int) $archive_max); queryfx($conn_w, 'INSERT INTO %T (counterName, counterValue) VALUES (%s, %d) ON DUPLICATE KEY UPDATE counterValue = %d', LiskDAO::COUNTER_TABLE_NAME, $old_table, $initial_counter + 1, $initial_counter + 1);