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

adapt to review

This commit is contained in:
Torsten Dittmann 2021-06-18 12:00:27 +02:00
parent 16e50e8b32
commit a3cc8c9ad2
4 changed files with 18 additions and 16 deletions

View file

@ -1698,15 +1698,15 @@ $collections = [
],
],
],
Database::SYSTEM_COLLECTION_REALTIME_CONNECTIONS => [
Database::SYSTEM_COLLECTION_CONNECTIONS => [
'$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS,
'$id' => Database::SYSTEM_COLLECTION_REALTIME_CONNECTIONS,
'$id' => Database::SYSTEM_COLLECTION_CONNECTIONS,
'$permissions' => ['read' => ['*']],
'name' => 'Realtime Connections',
'structure' => true,
'rules' => [
[
'$collection' => Database::SYSTEM_COLLECTION_REALTIME_CONNECTIONS,
'$collection' => Database::SYSTEM_COLLECTION_CONNECTIONS,
'label' => 'Container',
'key' => 'container',
'type' => Database::SYSTEM_VAR_TYPE_TEXT,
@ -1714,7 +1714,7 @@ $collections = [
'array' => false,
],
[
'$collection' => Database::SYSTEM_COLLECTION_REALTIME_CONNECTIONS,
'$collection' => Database::SYSTEM_COLLECTION_CONNECTIONS,
'label' => 'Timestamp',
'key' => 'timestamp',
'type' => Database::SYSTEM_VAR_TYPE_NUMERIC,
@ -1722,9 +1722,9 @@ $collections = [
'array' => false,
],
[
'$collection' => Database::SYSTEM_COLLECTION_REALTIME_CONNECTIONS,
'label' => 'Data',
'key' => 'data',
'$collection' => Database::SYSTEM_COLLECTION_CONNECTIONS,
'label' => 'Value',
'key' => 'value',
'type' => Database::SYSTEM_VAR_TYPE_TEXT,
'required' => true,
'array' => false,

View file

@ -39,7 +39,7 @@ $cli
]);
}
function notifyDeleteRealtimeUsage()
function notifyDeleteConnections()
{
Resque::enqueue(Event::DELETE_QUEUE_NAME, Event::DELETE_CLASS_NAME, [
'type' => DELETE_TYPE_REALTIME,
@ -59,6 +59,6 @@ $cli
notifyDeleteExecutionLogs($executionLogsRetention);
notifyDeleteAbuseLogs($abuseLogsRetention);
notifyDeleteAuditLogs($auditLogRetention);
notifyDeleteRealtimeUsage();
notifyDeleteConnections();
}, $interval);
});

View file

@ -43,7 +43,7 @@ class Database
const SYSTEM_COLLECTION_EXECUTIONS = 'executions';
// Realtime
const SYSTEM_COLLECTION_REALTIME_CONNECTIONS = 'realtimeConnections';
const SYSTEM_COLLECTION_CONNECTIONS = 'connections';
// Var Types
const SYSTEM_VAR_TYPE_TEXT = 'text';

View file

@ -125,14 +125,14 @@ class Server
try {
go(function() {
$document = [
'$collection' => Database::SYSTEM_COLLECTION_REALTIME_CONNECTIONS,
'$collection' => Database::SYSTEM_COLLECTION_CONNECTIONS,
'$permissions' => [
'read' => ['*'],
'write' => ['*'],
],
'container' => $this->server->container_id,
'timestamp' => time(),
'data' => '{}'
'value' => '{}'
];
Authorization::disable();
$document = $this->consoleDb->createDocument($document);
@ -147,6 +147,7 @@ class Server
}
// Run ever 10 seconds
Timer::tick(10000, function () {
/** @var Table $stats */
foreach ($this->usage as $projectId => $value) {
@ -177,6 +178,7 @@ class Server
}
});
// Run ever 10 seconds
Timer::tick(10000, function () {
$payload = [];
foreach ($this->usage as $projectId => $value) {
@ -189,14 +191,14 @@ class Server
}
$document = [
'$id' => $this->server->document_id,
'$collection' => Database::SYSTEM_COLLECTION_REALTIME_CONNECTIONS,
'$collection' => Database::SYSTEM_COLLECTION_CONNECTIONS,
'$permissions' => [
'read' => ['*'],
'write' => ['*'],
],
'container' => $this->server->container_id,
'timestamp' => time(),
'data' => json_encode($payload)
'value' => json_encode($payload)
];
try {
$document = $this->consoleDb->updateDocument($document);
@ -497,13 +499,13 @@ class Server
$payload = [];
$list = $this->consoleDb->getCollection([
'filters' => [
'$collection='.Database::SYSTEM_COLLECTION_REALTIME_CONNECTIONS,
'$collection='.Database::SYSTEM_COLLECTION_CONNECTIONS,
'timestamp>'.(time() - 15)
],
]);
foreach ($list as $document) {
foreach (json_decode($document->getAttribute('data')) as $projectId => $value) {
foreach (json_decode($document->getAttribute('value')) as $projectId => $value) {
if (array_key_exists($projectId, $payload)) {
$payload[$projectId] += $value;
} else {