Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/daemon/garbagecollector/PhabricatorDaemonTaskGarbageCollector.php
12256 views
1
<?php
2
3
final class PhabricatorDaemonTaskGarbageCollector
4
extends PhabricatorGarbageCollector {
5
6
const COLLECTORCONST = 'worker.tasks';
7
8
public function getCollectorName() {
9
return pht('Archived Tasks');
10
}
11
12
public function getDefaultRetentionPolicy() {
13
return phutil_units('14 days in seconds');
14
}
15
16
protected function collectGarbage() {
17
$table = new PhabricatorWorkerArchiveTask();
18
$data_table = new PhabricatorWorkerTaskData();
19
$conn_w = $table->establishConnection('w');
20
21
$tasks = id(new PhabricatorWorkerArchiveTaskQuery())
22
->withDateCreatedBefore($this->getGarbageEpoch())
23
->setLimit(100)
24
->execute();
25
if (!$tasks) {
26
return false;
27
}
28
29
$data_ids = array_filter(mpull($tasks, 'getDataID'));
30
$task_ids = mpull($tasks, 'getID');
31
32
$table->openTransaction();
33
if ($data_ids) {
34
queryfx(
35
$conn_w,
36
'DELETE FROM %T WHERE id IN (%Ld)',
37
$data_table->getTableName(),
38
$data_ids);
39
}
40
queryfx(
41
$conn_w,
42
'DELETE FROM %T WHERE id IN (%Ld)',
43
$table->getTableName(),
44
$task_ids);
45
$table->saveTransaction();
46
47
return (count($task_ids) == 100);
48
}
49
50
}
51
52