mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-18 12:52:42 +01:00
Garbage collect daemon logs
Summary: We already have GC for daemon log events, but not for daemon logs themselves. Collect old daemon logs which aren't still running. Test Plan: Ran `phd debug garbage`, observed old logs get cleaned up. Started some daemons, re-ran garbage, made sure they stuck around. Reviewers: joshuaspence Reviewed By: joshuaspence Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D9610
This commit is contained in:
parent
df2c015e7c
commit
df3736e81e
4 changed files with 32 additions and 3 deletions
2
resources/sql/autopatches/20140617.daemonlog.sql
Normal file
2
resources/sql/autopatches/20140617.daemonlog.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE {$NAMESPACE}_daemon.daemon_log
|
||||
ADD KEY (dateCreated);
|
|
@ -1454,6 +1454,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDaemonEventListener' => 'applications/daemon/event/PhabricatorDaemonEventListener.php',
|
||||
'PhabricatorDaemonLog' => 'applications/daemon/storage/PhabricatorDaemonLog.php',
|
||||
'PhabricatorDaemonLogEvent' => 'applications/daemon/storage/PhabricatorDaemonLogEvent.php',
|
||||
'PhabricatorDaemonLogEventGarbageCollector' => 'applications/daemon/garbagecollector/PhabricatorDaemonLogEventGarbageCollector.php',
|
||||
'PhabricatorDaemonLogEventViewController' => 'applications/daemon/controller/PhabricatorDaemonLogEventViewController.php',
|
||||
'PhabricatorDaemonLogEventsView' => 'applications/daemon/view/PhabricatorDaemonLogEventsView.php',
|
||||
'PhabricatorDaemonLogGarbageCollector' => 'applications/daemon/garbagecollector/PhabricatorDaemonLogGarbageCollector.php',
|
||||
|
@ -4265,6 +4266,7 @@ phutil_register_library_map(array(
|
|||
1 => 'PhabricatorPolicyInterface',
|
||||
),
|
||||
'PhabricatorDaemonLogEvent' => 'PhabricatorDaemonDAO',
|
||||
'PhabricatorDaemonLogEventGarbageCollector' => 'PhabricatorGarbageCollector',
|
||||
'PhabricatorDaemonLogEventViewController' => 'PhabricatorDaemonController',
|
||||
'PhabricatorDaemonLogEventsView' => 'AphrontView',
|
||||
'PhabricatorDaemonLogGarbageCollector' => 'PhabricatorGarbageCollector',
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorDaemonLogEventGarbageCollector
|
||||
extends PhabricatorGarbageCollector {
|
||||
|
||||
public function collectGarbage() {
|
||||
$ttl = PhabricatorEnv::getEnvConfig('gcdaemon.ttl.daemon-logs');
|
||||
if ($ttl <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$table = new PhabricatorDaemonLogEvent();
|
||||
$conn_w = $table->establishConnection('w');
|
||||
|
||||
queryfx(
|
||||
$conn_w,
|
||||
'DELETE FROM %T WHERE epoch < %d LIMIT 100',
|
||||
$table->getTableName(),
|
||||
time() - $ttl);
|
||||
|
||||
return ($conn_w->getAffectedRows() == 100);
|
||||
}
|
||||
|
||||
}
|
|
@ -9,14 +9,15 @@ final class PhabricatorDaemonLogGarbageCollector
|
|||
return false;
|
||||
}
|
||||
|
||||
$table = new PhabricatorDaemonLogEvent();
|
||||
$table = new PhabricatorDaemonLog();
|
||||
$conn_w = $table->establishConnection('w');
|
||||
|
||||
queryfx(
|
||||
$conn_w,
|
||||
'DELETE FROM %T WHERE epoch < %d LIMIT 100',
|
||||
'DELETE FROM %T WHERE dateCreated < %d AND status != %s LIMIT 100',
|
||||
$table->getTableName(),
|
||||
time() - $ttl);
|
||||
time() - $ttl,
|
||||
PhabricatorDaemonLog::STATUS_RUNNING);
|
||||
|
||||
return ($conn_w->getAffectedRows() == 100);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue