mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +01:00
Garbage collect Drydock logs after 30 days
Summary: Ref T9252. Drydock logs are almost exclusively useful as a diagnostic tool for debugging immediate problems, so GC them fairly aggressively. (I expect 99% of the usefulness of these logs to be within the first 24 hours, basically "why isn't my thing working". I can't really think of any cases where having old logs would be useful.) Test Plan: - Ran GC, saw it hit the log table (with no effect). - Changed TTL from 30 days to 30 seconds, ran GC, saw it wipe recent logs. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9252 Differential Revision: https://secure.phabricator.com/D14197
This commit is contained in:
parent
2ef5b5321d
commit
06f9272502
2 changed files with 24 additions and 0 deletions
|
@ -845,6 +845,7 @@ phutil_register_library_map(array(
|
|||
'DrydockLeaseWorker' => 'applications/drydock/worker/DrydockLeaseWorker.php',
|
||||
'DrydockLog' => 'applications/drydock/storage/DrydockLog.php',
|
||||
'DrydockLogController' => 'applications/drydock/controller/DrydockLogController.php',
|
||||
'DrydockLogGarbageCollector' => 'applications/drydock/garbagecollector/DrydockLogGarbageCollector.php',
|
||||
'DrydockLogListController' => 'applications/drydock/controller/DrydockLogListController.php',
|
||||
'DrydockLogListView' => 'applications/drydock/view/DrydockLogListView.php',
|
||||
'DrydockLogQuery' => 'applications/drydock/query/DrydockLogQuery.php',
|
||||
|
@ -4586,6 +4587,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPolicyInterface',
|
||||
),
|
||||
'DrydockLogController' => 'DrydockController',
|
||||
'DrydockLogGarbageCollector' => 'PhabricatorGarbageCollector',
|
||||
'DrydockLogListController' => 'DrydockLogController',
|
||||
'DrydockLogListView' => 'AphrontView',
|
||||
'DrydockLogQuery' => 'DrydockQuery',
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
final class DrydockLogGarbageCollector
|
||||
extends PhabricatorGarbageCollector {
|
||||
|
||||
public function collectGarbage() {
|
||||
$log_table = new DrydockLog();
|
||||
$conn_w = $log_table->establishConnection('w');
|
||||
|
||||
$now = PhabricatorTime::getNow();
|
||||
$ttl = phutil_units('30 days in seconds');
|
||||
|
||||
queryfx(
|
||||
$conn_w,
|
||||
'DELETE FROM %T WHERE epoch <= %d LIMIT 100',
|
||||
$log_table->getTableName(),
|
||||
$now - $ttl);
|
||||
|
||||
return ($conn_w->getAffectedRows() == 100);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue