@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final 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}