diff --git a/.env b/.env index b6e3f7a2e6..3406ba1004 100644 --- a/.env +++ b/.env @@ -35,4 +35,7 @@ _APP_FUNCTIONS_CPUS=1 _APP_FUNCTIONS_MEMORY=128 _APP_FUNCTIONS_MEMORY_SWAP=128 _APP_MAINTENANCE_INTERVAL=86400 -_APP_USAGE_STATS=enabled \ No newline at end of file +_APP_MAINTENANCE_RETENTION_EXECUTION=1209600 +_APP_MAINTENANCE_RETENTION_ABUSE=86400 +_APP_MAINTENANCE_RETENTION_AUDIT=1209600 +_APP_USAGE_STATS=enabled diff --git a/Dockerfile b/Dockerfile index 0017d68dcb..c7316bd1d4 100755 --- a/Dockerfile +++ b/Dockerfile @@ -100,7 +100,11 @@ ENV _APP_SERVER=swoole \ _APP_SETUP=self-hosted \ _APP_VERSION=$VERSION \ _APP_USAGE_STATS=enabled \ + # 14 Days = 1209600 s + _APP_MAINTENANCE_RETENTION_EXECUTION=1209600 \ + _APP_MAINTENANCE_RETENTION_AUDIT=1209600 \ # 1 Day = 86400 s + _APP_MAINTENANCE_RETENTION_ABUSE=86400 \ _APP_MAINTENANCE_INTERVAL=86400 #ENV _APP_SMTP_SECURE '' #ENV _APP_SMTP_USERNAME '' diff --git a/app/config/variables.php b/app/config/variables.php index 6215b18f7c..cd5d220f3f 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -364,6 +364,30 @@ return [ 'required' => false, 'question' => '', ], + [ + 'name' => '_APP_MAINTENANCE_RETENTION_EXECUTION', + 'description' => 'The maximum duration (in seconds) upto which to retain execution logs. The default value is 1209600 seconds (14 days).', + 'introduction' => '0.7.0', + 'default' => '1209600', + 'required' => false, + 'question' => '', + ], + [ + 'name' => '_APP_MAINTENANCE_RETENTION_AUDIT', + 'description' => 'IThe maximum duration (in seconds) upto which to retain audit logs. The default value is 1209600 seconds (14 days).', + 'introduction' => '0.7.0', + 'default' => '1209600', + 'required' => false, + 'question' => '', + ], + [ + 'name' => '_APP_MAINTENANCE_RETENTION_ABUSE', + 'description' => 'The maximum duration (in seconds) upto which to retain abuse logs. The default value is 86400 seconds (1 day).', + 'introduction' => '0.7.0', + 'default' => '86400', + 'required' => false, + 'question' => '', + ] ], ], ], diff --git a/app/tasks/maintenance.php b/app/tasks/maintenance.php index 34c34cfb83..78a31e6dda 100644 --- a/app/tasks/maintenance.php +++ b/app/tasks/maintenance.php @@ -12,10 +12,11 @@ Console::title('Maintenance V1'); Console::success(APP_NAME.' maintenance process v1 has started'); -function notifyDeleteExecutionLogs() +function notifyDeleteExecutionLogs(int $interval) { Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [ - 'type' => DELETE_TYPE_EXECUTIONS + 'type' => DELETE_TYPE_EXECUTIONS, + 'timestamp' => time() - $interval ]); } @@ -41,14 +42,15 @@ $cli ->action(function () { // # of days in seconds (1 day = 86400s) $interval = (int) App::getEnv('_APP_MAINTENANCE_INTERVAL', '86400'); + $executionLogsRetention = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_EXECUTION', '1209600'); + $auditLogRetention = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_AUDIT', '1209600'); + $abuseLogsRetention = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_ABUSE', '86400'); - Console::loop(function() use ($interval){ + Console::loop(function() use ($interval, $executionLogsRetention, $abuseLogsRetention, $auditLogRetention){ $time = date('d-m-Y H:i:s', time()); Console::info("[{$time}] Notifying deletes workers every {$interval} seconds"); - notifyDeleteExecutionLogs(); - notifyDeleteAbuseLogs($interval); - notifyDeleteAuditLogs($interval); - + notifyDeleteExecutionLogs($executionLogsRetention); + notifyDeleteAbuseLogs($abuseLogsRetention); + notifyDeleteAuditLogs($auditLogRetention); }, $interval); - }); \ No newline at end of file diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index 098d4d4070..231d2f857b 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -279,11 +279,10 @@ services: - _APP_REDIS_HOST - _APP_REDIS_PORT - _APP_MAINTENANCE_INTERVAL - - _APP_DB_HOST - - _APP_DB_PORT - - _APP_DB_SCHEMA - - _APP_DB_USER - - _APP_DB_PASS + - _APP_MAINTENANCE_RETENTION_EXECUTION + - _APP_MAINTENANCE_RETENTION_ABUSE + - _APP_MAINTENANCE_RETENTION_AUDIT + appwrite-schedule: image: appwrite/appwrite: diff --git a/app/workers/deletes.php b/app/workers/deletes.php index cf9aa2c453..ac168d6bcb 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -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); }); } diff --git a/docker-compose.yml b/docker-compose.yml index e9d82cbf0f..e601ae7086 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -329,6 +329,9 @@ services: - _APP_REDIS_HOST - _APP_REDIS_PORT - _APP_MAINTENANCE_INTERVAL + - _APP_MAINTENANCE_RETENTION_EXECUTION + - _APP_MAINTENANCE_RETENTION_ABUSE + - _APP_MAINTENANCE_RETENTION_AUDIT appwrite-schedule: entrypoint: schedule