Merge pull request #10482 from appwrite/fix-db-queues

fix: health db queues
This commit is contained in:
Luke B. Silver 2025-09-12 19:58:46 +01:00 committed by GitHub
commit b5c588722b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 9 deletions

View file

@ -538,7 +538,7 @@ App::get('/v1/health/queue/databases')
->inject('response')
->action(function (string $name, int|string $threshold, Database $queueForDatabase, Response $response) {
$threshold = \intval($threshold);
$size = $queueForDatabase->getSize();
$size = $queueForDatabase->setQueue($name)->getSize();
if ($size >= $threshold) {
throw new Exception(Exception::HEALTH_QUEUE_SIZE_EXCEEDED, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}.");

View file

@ -161,17 +161,20 @@ class Database extends Event
return $this->document;
}
public function getQueue(): string
public function setProject(Document $project): self
{
try {
$dsn = new DSN($this->getProject()->getAttribute('database'));
} catch (\InvalidArgumentException) {
// TODO: Temporary until all projects are using shared tables
$dsn = new DSN('mysql://' . $this->getProject()->getAttribute('database'));
$database = $project->getAttribute('database');
if (!empty($database)) {
try {
$dsn = new DSN($database);
} catch (\InvalidArgumentException) {
// TODO: Temporary until all projects are using shared tables
$dsn = new DSN("mysql://$database");
}
$this->queue = $dsn->getHost();
}
$this->queue = $dsn->getHost();
return $this->queue;
return parent::setProject($project);
}
/**