1
0
Fork 0
mirror of synced 2024-05-20 12:42:39 +12:00

feat(maintenance): add realtime usage stats

This commit is contained in:
Torsten Dittmann 2021-06-16 11:35:37 +02:00
parent 8102b4f908
commit 554d3c3557
3 changed files with 27 additions and 0 deletions

View file

@ -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';

View file

@ -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);
});

View file

@ -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);