feat: add filter to delete execution logs older than
This commit is contained in:
parent
e85fc0282e
commit
04f14816d7
|
@ -100,8 +100,11 @@ ENV _APP_SERVER=swoole \
|
|||
_APP_SETUP=self-hosted \
|
||||
_APP_VERSION=$VERSION \
|
||||
_APP_USAGE_STATS=enabled \
|
||||
# 14 Days = 1209600 s
|
||||
_APP_MAINTENANCE_EXECUTION_LOG_RETENTION=1209600 \
|
||||
_APP_MAINTENANCE_AUDIT_LOG_RETENTION=1209600 \
|
||||
# 1 Day = 86400 s
|
||||
_APP_MAINTENANCE_INTERVAL=86400
|
||||
_APP_MAINTENANCE_ABUSE_LOG_RETENTION=86400 \
|
||||
#ENV _APP_SMTP_SECURE ''
|
||||
#ENV _APP_SMTP_USERNAME ''
|
||||
#ENV _APP_SMTP_PASSWORD ''
|
||||
|
|
|
@ -12,26 +12,27 @@ Console::title('Maintenance V1');
|
|||
|
||||
Console::success(APP_NAME.' maintenance process v1 has started');
|
||||
|
||||
function notifyDeleteExecutionLogs()
|
||||
function notifyDeleteExecutionLogs(int $retention)
|
||||
{
|
||||
Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [
|
||||
'type' => DELETE_TYPE_EXECUTIONS
|
||||
'type' => DELETE_TYPE_EXECUTIONS,
|
||||
'timestamp' => time() - $retention
|
||||
]);
|
||||
}
|
||||
|
||||
function notifyDeleteAbuseLogs(int $interval)
|
||||
function notifyDeleteAbuseLogs(int $retention)
|
||||
{
|
||||
Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [
|
||||
'type' => DELETE_TYPE_ABUSE,
|
||||
'timestamp' => time() - $interval
|
||||
'timestamp' => time() - $retention
|
||||
]);
|
||||
}
|
||||
|
||||
function notifyDeleteAuditLogs(int $interval)
|
||||
function notifyDeleteAuditLogs(int $retention)
|
||||
{
|
||||
Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [
|
||||
'type' => DELETE_TYPE_AUDIT,
|
||||
'timestamp' => time() - $interval
|
||||
'timestamp' => time() - $retention
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -40,15 +41,30 @@ $cli
|
|||
->desc('Schedules maintenance tasks and publishes them to resque')
|
||||
->action(function () {
|
||||
// # of days in seconds (1 day = 86400s)
|
||||
$interval = (int) App::getEnv('_APP_MAINTENANCE_INTERVAL', '86400');
|
||||
// $executionLogsRetention = (int) App::getEnv('_APP_MAINTENANCE_EXECUTION_LOG_RETENTION', '60');
|
||||
$executionLogsRetention = 120;
|
||||
$abuseLogsRetention = (int) App::getEnv('_APP_MAINTENANCE_ABUSE_LOG_RETENTION', '60');
|
||||
$auditLogRetention = (int) App::getEnv('_APP_MAINTENANCE_AUDIT_LOG_RETENTION', '60');
|
||||
|
||||
Console::loop(function() use ($interval){
|
||||
// Schedule delete execution logs
|
||||
Console::loop(function() use ($executionLogsRetention){
|
||||
$time = date('d-m-Y H:i:s', time());
|
||||
Console::info("[{$time}] Notifying deletes workers every {$interval} seconds");
|
||||
notifyDeleteExecutionLogs();
|
||||
notifyDeleteAbuseLogs($interval);
|
||||
notifyDeleteAuditLogs($interval);
|
||||
|
||||
}, $interval);
|
||||
Console::info("[{$time}] Notifying deletes workers every {$executionLogsRetention} seconds");
|
||||
notifyDeleteExecutionLogs($executionLogsRetention);
|
||||
}, $executionLogsRetention);
|
||||
|
||||
// // Schedule delete abuse logs
|
||||
// Console::loop(function() use ($abuseLogsRetention){
|
||||
// $time = date('d-m-Y H:i:s', time());
|
||||
// Console::info("[{$time}] Notifying deletes workers every {$abuseLogsRetention} seconds");
|
||||
// notifyDeleteAbuseLogs($abuseLogsRetention);
|
||||
// }, $abuseLogsRetention);
|
||||
|
||||
// // Schedule delete audit logs
|
||||
// Console::loop(function() use ($auditLogRetention){
|
||||
// $time = date('d-m-Y H:i:s', time());
|
||||
// Console::info("[{$time}] Notifying deletes workers every {$auditLogRetention} seconds");
|
||||
// notifyDeleteAuditLogs($auditLogRetention);
|
||||
// }, $auditLogRetention);
|
||||
|
||||
});
|
|
@ -59,7 +59,7 @@ class DeletesV1
|
|||
break;
|
||||
|
||||
case DELETE_TYPE_EXECUTIONS:
|
||||
$this->deleteExecutionLogs();
|
||||
$this->deleteExecutionLogs($this->args['timestamp']);
|
||||
break;
|
||||
|
||||
case DELETE_TYPE_AUDIT:
|
||||
|
@ -121,16 +121,17 @@ class DeletesV1
|
|||
], $this->getProjectDB($projectId));
|
||||
}
|
||||
|
||||
protected function deleteExecutionLogs()
|
||||
protected function deleteExecutionLogs($timestamp)
|
||||
{
|
||||
$this->deleteForProjectIds(function($projectId) {
|
||||
$this->deleteForProjectIds(function($projectId) use ($timestamp) {
|
||||
if (!($projectDB = $this->getProjectDB($projectId))) {
|
||||
throw new Exception('Failed to get projectDB for project '.$projectId);
|
||||
}
|
||||
|
||||
// Delete Executions
|
||||
$this->deleteByGroup([
|
||||
'$collection='.Database::SYSTEM_COLLECTION_EXECUTIONS
|
||||
'$collection='.Database::SYSTEM_COLLECTION_EXECUTIONS,
|
||||
'dateCreated<'.$timestamp
|
||||
], $projectDB);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue