From 72ee7d7f343485cdb27cb7229e2353a9dc17de9d Mon Sep 17 00:00:00 2001 From: shimon Date: Thu, 8 Feb 2024 20:51:54 +0200 Subject: [PATCH] interval update --- .env | 2 +- src/Appwrite/Platform/Workers/Usage.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.env b/.env index 3efd72e2a2..b915f91516 100644 --- a/.env +++ b/.env @@ -78,7 +78,7 @@ _APP_MAINTENANCE_RETENTION_CACHE=2592000 _APP_MAINTENANCE_RETENTION_EXECUTION=1209600 _APP_MAINTENANCE_RETENTION_ABUSE=86400 _APP_MAINTENANCE_RETENTION_AUDIT=1209600 -_APP_USAGE_AGGREGATION_INTERVAL=60 +_APP_USAGE_AGGREGATION_INTERVAL=20 _APP_MAINTENANCE_RETENTION_USAGE_HOURLY=8640000 _APP_MAINTENANCE_RETENTION_SCHEDULES=86400 _APP_USAGE_STATS=enabled diff --git a/src/Appwrite/Platform/Workers/Usage.php b/src/Appwrite/Platform/Workers/Usage.php index 859fa6f97e..78efca3585 100644 --- a/src/Appwrite/Platform/Workers/Usage.php +++ b/src/Appwrite/Platform/Workers/Usage.php @@ -5,6 +5,7 @@ namespace Appwrite\Platform\Workers; use Exception; use Utopia\App; use Utopia\CLI\Console; +use Utopia\Database\DateTime; use Utopia\Database\Document; use Utopia\Platform\Action; use Appwrite\Event\UsageDump; @@ -58,7 +59,7 @@ class Usage extends Action } //Todo Figure out way to preserve keys when the container is being recreated @shimonewman - $aggregationInterval = (int) App::getEnv('_APP_USAGE_AGGREGATION_INTERVAL', '60'); + $aggregationInterval = (int) App::getEnv('_APP_USAGE_AGGREGATION_INTERVAL', '20'); $project = new Document($payload['project'] ?? []); $projectId = $project->getInternalId(); foreach ($payload['reduce'] ?? [] as $document) { @@ -84,12 +85,12 @@ class Usage extends Action $this->stats[$projectId]['keys'][$metric['key']] += $metric['value']; } - // if keys crossed threshold or X time passed since the last send and there are some keys in the array ($this->stats) if ( $this->keys >= self::KEYS_THRESHOLD || (time() - $this->lastTriggeredTime > $aggregationInterval && $this->keys > 0) ) { + var_dump(DateTime::now()); $queueForUsageDump ->setStats($this->stats) ->trigger();