fix: realtime and missing index
This commit is contained in:
parent
db35fc92d5
commit
79205cdccc
|
@ -1177,6 +1177,13 @@ $collections = [
|
||||||
'lengths' => [320],
|
'lengths' => [320],
|
||||||
'orders' => [Database::ORDER_ASC],
|
'orders' => [Database::ORDER_ASC],
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'$id' => '_key_phone',
|
||||||
|
'type' => Database::INDEX_UNIQUE,
|
||||||
|
'attributes' => ['phone'],
|
||||||
|
'lengths' => [16],
|
||||||
|
'orders' => [Database::ORDER_ASC],
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'$id' => '_key_search',
|
'$id' => '_key_search',
|
||||||
'type' => Database::INDEX_FULLTEXT,
|
'type' => Database::INDEX_FULLTEXT,
|
||||||
|
@ -1744,7 +1751,7 @@ $collections = [
|
||||||
'orders' => [Database::ORDER_ASC, Database::ORDER_ASC],
|
'orders' => [Database::ORDER_ASC, Database::ORDER_ASC],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'$id' => '_key_internal',
|
'$id' => '_key_user',
|
||||||
'type' => Database::INDEX_KEY,
|
'type' => Database::INDEX_KEY,
|
||||||
'attributes' => ['userInternalId'],
|
'attributes' => ['userInternalId'],
|
||||||
'lengths' => [Database::LENGTH_KEY],
|
'lengths' => [Database::LENGTH_KEY],
|
||||||
|
|
|
@ -113,7 +113,7 @@ function getDatabase(Registry &$register, string $namespace)
|
||||||
throw new Exception('Collection not ready');
|
throw new Exception('Collection not ready');
|
||||||
}
|
}
|
||||||
break; // leave loop if successful
|
break; // leave loop if successful
|
||||||
} catch (\Exception $e) {
|
} catch (\Throwable $e) {
|
||||||
Console::warning("Database not ready. Retrying connection ({$attempts})...");
|
Console::warning("Database not ready. Retrying connection ({$attempts})...");
|
||||||
if ($attempts >= DATABASE_RECONNECT_MAX_ATTEMPTS) {
|
if ($attempts >= DATABASE_RECONNECT_MAX_ATTEMPTS) {
|
||||||
throw new \Exception('Failed to connect to database: ' . $e->getMessage());
|
throw new \Exception('Failed to connect to database: ' . $e->getMessage());
|
||||||
|
@ -138,25 +138,30 @@ $server->onStart(function () use ($stats, $register, $containerId, &$statsDocume
|
||||||
/**
|
/**
|
||||||
* Create document for this worker to share stats across Containers.
|
* Create document for this worker to share stats across Containers.
|
||||||
*/
|
*/
|
||||||
go(function () use ($register, $containerId, &$statsDocument, $logError) {
|
go(function () use ($register, $containerId, &$statsDocument) {
|
||||||
try {
|
$attempts = 0;
|
||||||
[$database, $returnDatabase] = getDatabase($register, '_console');
|
[$database, $returnDatabase] = getDatabase($register, '_console');
|
||||||
$document = new Document([
|
do {
|
||||||
'$id' => $database->getId(),
|
try {
|
||||||
'$collection' => 'realtime',
|
$attempts++;
|
||||||
'$read' => [],
|
$document = new Document([
|
||||||
'$write' => [],
|
'$id' => $database->getId(),
|
||||||
'container' => $containerId,
|
'$collection' => 'realtime',
|
||||||
'timestamp' => time(),
|
'$read' => [],
|
||||||
'value' => '{}'
|
'$write' => [],
|
||||||
]);
|
'container' => $containerId,
|
||||||
|
'timestamp' => time(),
|
||||||
|
'value' => '{}'
|
||||||
|
]);
|
||||||
|
|
||||||
$statsDocument = Authorization::skip(fn () => $database->createDocument('realtime', $document));
|
$statsDocument = Authorization::skip(fn () => $database->createDocument('realtime', $document));
|
||||||
} catch (\Throwable $th) {
|
break;
|
||||||
call_user_func($logError, $th, "createWorkerDocument");
|
} catch (\Throwable $th) {
|
||||||
} finally {
|
Console::warning("Collection not ready. Retrying connection ({$attempts})...");
|
||||||
call_user_func($returnDatabase);
|
sleep(DATABASE_RECONNECT_SLEEP);
|
||||||
}
|
}
|
||||||
|
} while (true);
|
||||||
|
call_user_func($returnDatabase);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue