From 554d3c355749039230ebc1f15bb31f280ce6db9f Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 16 Jun 2021 11:35:37 +0200 Subject: [PATCH] feat(maintenance): add realtime usage stats --- app/init.php | 1 + app/tasks/maintenance.php | 9 +++++++++ app/workers/deletes.php | 17 +++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/app/init.php b/app/init.php index cb87697a83..ad1a9bd3a6 100644 --- a/app/init.php +++ b/app/init.php @@ -69,6 +69,7 @@ const DELETE_TYPE_EXECUTIONS = 'executions'; const DELETE_TYPE_AUDIT = 'audit'; const DELETE_TYPE_ABUSE = 'abuse'; const DELETE_TYPE_CERTIFICATES = 'certificates'; +const DELETE_TYPE_REALTIME = 'realtime'; // Auth Types const APP_AUTH_TYPE_SESSION = 'Session'; const APP_AUTH_TYPE_JWT = 'JWT'; diff --git a/app/tasks/maintenance.php b/app/tasks/maintenance.php index eccdf61b17..a4db6ac4ec 100644 --- a/app/tasks/maintenance.php +++ b/app/tasks/maintenance.php @@ -39,6 +39,14 @@ $cli ]); } + function notifyDeleteRealtimeUsage() + { + Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [ + 'type' => DELETE_TYPE_REALTIME, + 'timestamp' => time() - 60 + ]); + } + // # of days in seconds (1 day = 86400s) $interval = (int) App::getEnv('_APP_MAINTENANCE_INTERVAL', '86400'); $executionLogsRetention = (int) App::getEnv('_APP_MAINTENANCE_RETENTION_EXECUTION', '1209600'); @@ -51,5 +59,6 @@ $cli notifyDeleteExecutionLogs($executionLogsRetention); notifyDeleteAbuseLogs($abuseLogsRetention); notifyDeleteAuditLogs($auditLogRetention); + notifyDeleteRealtimeUsage(); }, $interval); }); \ No newline at end of file diff --git a/app/workers/deletes.php b/app/workers/deletes.php index 63551e90f9..0080d35f36 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -69,6 +69,10 @@ class DeletesV1 extends Worker $this->deleteAbuseLogs($this->args['timestamp']); break; + case DELETE_TYPE_REALTIME: + $this->deleteRealtimeUsage($this->args['timestamp']); + break; + case DELETE_TYPE_CERTIFICATES: $document = new Document($this->args['document']); $this->deleteCertificates($document); @@ -197,6 +201,19 @@ class DeletesV1 extends Worker }); } + protected function deleteRealtimeUsage($timestamp) + { + if (!($consoleDB = $this->getConsoleDB())) { + throw new Exception('Failed to get consoleDb.'); + } + // Delete Dead Realtime Logs + $this->deleteByGroup([ + '$collection='.Database::SYSTEM_COLLECTION_REALTIME_CONNECTIONS, + 'timestamp<'.$timestamp + ], $consoleDB); + + } + protected function deleteFunction(Document $document, $projectId) { $projectDB = $this->getProjectDB($projectId);