1
0
Fork 0
mirror of synced 2024-05-09 23:32:38 +12:00
appwrite/app/tasks/maintenance.php

74 lines
3 KiB
PHP
Raw Normal View History

2020-12-15 05:39:44 +13:00
<?php
global $cli;
use Appwrite\Event\Event;
2020-12-15 05:39:44 +13:00
use Utopia\App;
use Utopia\CLI\Console;
$cli
->task('maintenance')
->desc('Schedules maintenance tasks and publishes them to resque')
->action(function () {
2021-01-27 09:49:13 +13:00
Console::title('Maintenance V1');
Console::success(APP_NAME.' maintenance process v1 has started');
function notifyDeleteExecutionLogs(int $interval)
{
Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [
'type' => DELETE_TYPE_EXECUTIONS,
'timestamp' => time() - $interval
]);
}
function notifyDeleteAbuseLogs(int $interval)
{
Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [
'type' => DELETE_TYPE_ABUSE,
'timestamp' => time() - $interval
]);
}
function notifyDeleteAuditLogs(int $interval)
{
Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [
'type' => DELETE_TYPE_AUDIT,
'timestamp' => time() - $interval
]);
}
2021-08-27 23:37:52 +12:00
function notifyDeleteUsageStats(int $interval30m, int $interval1d)
{
Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [
'type' => DELETE_TYPE_USAGE,
2021-09-07 17:18:30 +12:00
'timestamp1d' => time() - $interval1d,
'timestamp30m' => time() - $interval30m,
2021-08-27 23:37:52 +12:00
]);
}
2021-06-18 22:00:27 +12:00
function notifyDeleteConnections()
{
Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [
'type' => DELETE_TYPE_REALTIME,
'timestamp' => time() - 60
]);
}
2020-12-18 23:48:00 +13:00
// # of days in seconds (1 day = 86400s)
2021-01-21 06:57:49 +13:00
$interval = (int) App::getEnv('_APP_MAINTENANCE_INTERVAL', '86400');
2021-01-21 07:23:48 +13:00
$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');
2021-08-27 23:37:52 +12:00
$usageStatsRetention30m = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_USAGE_30M', '129600');//36 hours
$usageStatsRetention1d = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_USAGE_1D', '8640000'); // 100 days
2020-12-15 10:26:37 +13:00
2021-09-02 18:32:32 +12:00
Console::loop(function() use ($interval, $executionLogsRetention, $abuseLogsRetention, $auditLogRetention, $usageStatsRetention30m, $usageStatsRetention1d) {
2021-01-17 19:17:19 +13:00
$time = date('d-m-Y H:i:s', time());
2021-01-21 06:57:49 +13:00
Console::info("[{$time}] Notifying deletes workers every {$interval} seconds");
notifyDeleteExecutionLogs($executionLogsRetention);
2021-01-21 06:57:49 +13:00
notifyDeleteAbuseLogs($abuseLogsRetention);
notifyDeleteAuditLogs($auditLogRetention);
2021-09-02 18:32:32 +12:00
notifyDeleteUsageStats($usageStatsRetention30m, $usageStatsRetention1d);
2021-06-18 22:00:27 +12:00
notifyDeleteConnections();
2021-01-21 06:57:49 +13:00
}, $interval);
2020-12-15 05:39:44 +13:00
});