mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 08:58:35 +00:00
Merge pull request #10054 from appwrite/chore-fix-tasks
refactor: replace Console loop with Swoole Timer for stats resource m…
This commit is contained in:
commit
1dfba85bcc
2 changed files with 65 additions and 0 deletions
|
|
@ -3,7 +3,10 @@
|
|||
namespace Appwrite\Platform;
|
||||
|
||||
use Swoole\Coroutine as Co;
|
||||
use Utopia\CLI\Console;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Platform\Action as UtopiaAction;
|
||||
|
||||
|
|
@ -16,6 +19,12 @@ class Action extends UtopiaAction
|
|||
*/
|
||||
protected mixed $logError;
|
||||
|
||||
protected array $filters = [
|
||||
'subQueryKeys', 'subQueryWebhooks', 'subQueryPlatforms', 'subQueryProjectVariables', 'subQueryBlocks', 'subQueryDevKeys', // Project
|
||||
'subQueryAuthenticators', 'subQuerySessions', 'subQueryTokens', 'subQueryChallenges', 'subQueryMemberships', 'subQueryTargets', 'subQueryTopicTargets',// Users
|
||||
'subQueryVariables', // Sites
|
||||
];
|
||||
|
||||
/**
|
||||
* Foreach Document
|
||||
* Call provided callback for each document in the collection
|
||||
|
|
@ -87,4 +96,57 @@ class Action extends UtopiaAction
|
|||
$latestDocument = $results[array_key_last($results)];
|
||||
}
|
||||
}
|
||||
|
||||
public function disableSubqueries()
|
||||
{
|
||||
$filters = $this->filters;
|
||||
|
||||
foreach ($filters as $filter) {
|
||||
Database::addFilter(
|
||||
$filter,
|
||||
function (mixed $value) {
|
||||
return;
|
||||
},
|
||||
function (mixed $value, Document $document, Database $database) {
|
||||
return [];
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump Log Message
|
||||
*
|
||||
* Logs messages to console with timestamp, method context, and project details.
|
||||
* Supports multiple log types: success, error, log, warning, and info (default).
|
||||
*
|
||||
* @param string $method The calling method name
|
||||
* @param string $log The log message
|
||||
* @param string $type The log type (success, error, log, warning, info)
|
||||
* @param Document|null $project The project document for context
|
||||
* @param string $collectionId The collection identifier
|
||||
* @return void
|
||||
*/
|
||||
public function dump(string $method, string $log, string $type = 'info', ?Document $project = null, string $collectionId = ''): void
|
||||
{
|
||||
if (empty($project)) {
|
||||
$project = new Document([]);
|
||||
}
|
||||
switch ($type) {
|
||||
case 'success':
|
||||
Console::success("[" . DateTime::now() . "] " . $method . ' ' . $type . ' ' . $project->getSequence() . ' ' . $project->getId() . ' ' . $collectionId . ' ' . $log);
|
||||
break;
|
||||
case 'error':
|
||||
Console::error("[" . DateTime::now() . "] " . $method . ' ' . $type . ' ' . $project->getSequence() . ' ' . $project->getId() . ' ' . $collectionId . ' ' . $log);
|
||||
break;
|
||||
case 'log':
|
||||
Console::log("[" . DateTime::now() . "] " . $method . ' ' . $type . ' ' . $project->getSequence() . ' ' . $project->getId() . ' ' . $collectionId . ' ' . $log);
|
||||
break;
|
||||
case 'warning':
|
||||
Console::warning("[" . DateTime::now() . "] " . $method . ' ' . $type . ' ' . $project->getSequence() . ' ' . $project->getId() . ' ' . $collectionId . ' ' . $log);
|
||||
break;
|
||||
default:
|
||||
Console::info("[" . DateTime::now() . "] " . $method . ' ' . $type . ' ' . $project->getSequence() . ' ' . $project->getId() . ' ' . $collectionId . ' ' . $log);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,11 +53,14 @@ class StatsResources extends Action
|
|||
$this->logError = $logError;
|
||||
$this->dbForPlatform = $dbForPlatform;
|
||||
|
||||
$this->disableSubqueries();
|
||||
|
||||
Console::title("Stats resources V1");
|
||||
|
||||
Console::success('Stats resources: started');
|
||||
|
||||
$interval = (int) System::getEnv('_APP_STATS_RESOURCES_INTERVAL', '3600');
|
||||
|
||||
Console::loop(function () use ($queue) {
|
||||
Authorization::disable();
|
||||
Authorization::setDefaultStatus(false);
|
||||
|
|
|
|||
Loading…
Reference in a new issue