diff --git a/.env b/.env index 92aaee3ae2..d514529a91 100644 --- a/.env +++ b/.env @@ -34,6 +34,7 @@ _APP_FUNCTIONS_CONTAINERS=10 _APP_FUNCTIONS_CPUS=1 _APP_FUNCTIONS_MEMORY=128 _APP_FUNCTIONS_MEMORY_SWAP=128 +_APP_MAINTENANCE_INTERVAL=86400 _APP_MAINTENANCE_EXECUTION_LOG_RETENTION=1209600 _APP_MAINTENANCE_ABUSE_LOG_RETENTION=86400 _APP_MAINTENANCE_AUDIT_LOG_RETENTION=1209600 diff --git a/Dockerfile b/Dockerfile index c116e34fb2..0f97e3ec48 100755 --- a/Dockerfile +++ b/Dockerfile @@ -104,7 +104,8 @@ ENV _APP_SERVER=swoole \ _APP_MAINTENANCE_EXECUTION_LOG_RETENTION=1209600 \ _APP_MAINTENANCE_AUDIT_LOG_RETENTION=1209600 \ # 1 Day = 86400 s - _APP_MAINTENANCE_ABUSE_LOG_RETENTION=86400 + _APP_MAINTENANCE_ABUSE_LOG_RETENTION=86400 \ + _APP_MAINTENANCE_INTERVAL=86400 #ENV _APP_SMTP_SECURE '' #ENV _APP_SMTP_USERNAME '' #ENV _APP_SMTP_PASSWORD '' diff --git a/app/config/variables.php b/app/config/variables.php index a52f1950c5..f662d57689 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -356,9 +356,17 @@ return [ 'category' => 'Maintenance', 'description' => '', 'variables' => [ + [ + 'name' => '_APP_MAINTENANCE_INTERVAL', + 'description' => 'Interval value containing the number of seconds that the Appwrite maintenance process should wait before executing system cleanups and optimizations. The default value is 86400 seconds (1 day).', + 'introduction' => '0.7.0', + 'default' => '86400', + 'required' => false, + 'question' => '', + ], [ 'name' => '_APP_MAINTENANCE_EXECUTION_LOG_RETENTION', - 'description' => 'Interval value containing the number of seconds that the Appwrite maintenance process should wait before cleaning up the execution logs. The default value is 1209600 seconds (14 days).', + 'description' => 'The maximum time period . The default value is 1209600 seconds (14 days).', 'introduction' => '0.7.0', 'default' => '1209600', 'required' => false, diff --git a/app/tasks/maintenance.php b/app/tasks/maintenance.php index cc15a4dced..df4005593d 100644 --- a/app/tasks/maintenance.php +++ b/app/tasks/maintenance.php @@ -12,27 +12,27 @@ Console::title('Maintenance V1'); Console::success(APP_NAME.' maintenance process v1 has started'); -function notifyDeleteExecutionLogs(int $retention) +function notifyDeleteExecutionLogs(int $interval) { Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [ 'type' => DELETE_TYPE_EXECUTIONS, - 'timestamp' => time() - $retention + 'timestamp' => time() - $interval ]); } -function notifyDeleteAbuseLogs(int $retention) +function notifyDeleteAbuseLogs(int $interval) { Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [ 'type' => DELETE_TYPE_ABUSE, - 'timestamp' => time() - $retention + 'timestamp' => time() - $interval ]); } -function notifyDeleteAuditLogs(int $retention) +function notifyDeleteAuditLogs(int $interval) { Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [ 'type' => DELETE_TYPE_AUDIT, - 'timestamp' => time() - $retention + 'timestamp' => time() - $interval ]); } @@ -41,30 +41,16 @@ $cli ->desc('Schedules maintenance tasks and publishes them to resque') ->action(function () { // # of days in seconds (1 day = 86400s) - // $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'); + $interval = (int) App::getEnv('_APP_MAINTENANCE_INTERVAL', '86400'); + $executionLogsRetention = (int) App::getEnv('_APP_MAINTENANCE_EXECUTION_LOG_RETENTION', '1209600'); + $auditLogRetention = (int) App::getEnv('_APP_MAINTENANCE_AUDIT_LOG_RETENTION', '1209600'); + $abuseLogsRetention = (int) App::getEnv('_APP_MAINTENANCE_ABUSE_LOG_RETENTION', '86400'); - // Schedule delete execution logs - Console::loop(function() use ($executionLogsRetention){ + Console::loop(function() use ($interval, $executionLogsRetention, $abuseLogsRetention, $auditLogRetention){ $time = date('d-m-Y H:i:s', time()); - Console::info("[{$time}] Notifying deletes workers every {$executionLogsRetention} seconds"); + Console::info("[{$time}] Notifying deletes workers every {$interval} 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); - + notifyDeleteAbuseLogs($abuseLogsRetention); + notifyDeleteAuditLogs($auditLogRetention); + }, $interval); }); \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 8d2de20462..9d47f10245 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -328,6 +328,7 @@ services: - _APP_ENV - _APP_REDIS_HOST - _APP_REDIS_PORT + - _APP_MAINTENANCE_INTERVAL - _APP_MAINTENANCE_EXECUTION_LOG_RETENTION - _APP_MAINTENANCE_ABUSE_LOG_RETENTION - _APP_MAINTENANCE_AUDIT_LOG_RETENTION