update error attribute

This commit is contained in:
Everly Precia Suresh 2022-11-08 17:06:50 +00:00
parent b011f931c5
commit 13ea6a5e69

View file

@ -5,7 +5,8 @@ use Appwrite\Messaging\Adapter\Realtime;
use Appwrite\Resque\Worker; use Appwrite\Resque\Worker;
use Utopia\CLI\Console; use Utopia\CLI\Console;
use Utopia\Database\Document; use Utopia\Database\Document;
use Utopia\Database\Exception; use Exception;
use Utopia\Database\Exception as DatabaseException;
require_once __DIR__ . '/../init.php'; require_once __DIR__ . '/../init.php';
@ -27,11 +28,11 @@ class DatabaseV1 extends Worker
$database = new Document($this->args['database'] ?? []); $database = new Document($this->args['database'] ?? []);
if ($collection->isEmpty()) { if ($collection->isEmpty()) {
throw new Exception('Missing collection'); throw new DatabaseException('Missing collection');
} }
if ($document->isEmpty()) { if ($document->isEmpty()) {
throw new Exception('Missing document'); throw new DatabaseException('Missing document');
} }
switch (strval($type)) { switch (strval($type)) {
@ -94,10 +95,10 @@ class DatabaseV1 extends Worker
try { try {
if (!$dbForProject->createAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key, $type, $size, $required, $default, $signed, $array, $format, $formatOptions, $filters)) { if (!$dbForProject->createAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key, $type, $size, $required, $default, $signed, $array, $format, $formatOptions, $filters)) {
throw new Exception('Failed to create Attribute'); throw new DatabaseException('Failed to create Attribute');
} }
$dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available')); $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available'));
} catch (Exception $e) { } catch (DatabaseException $e) {
Console::error($e->getMessage()); Console::error($e->getMessage());
$dbForProject->updateDocument( $dbForProject->updateDocument(
'attributes', 'attributes',
@ -106,14 +107,13 @@ class DatabaseV1 extends Worker
->setAttribute('status', 'failed') ->setAttribute('status', 'failed')
->setAttribute('error', $e->getMessage()) ->setAttribute('error', $e->getMessage())
); );
} catch (\Throwable $th) { } catch (Exception $e) {
Console::error('Internal Error');
$dbForProject->updateDocument( $dbForProject->updateDocument(
'attributes', 'attributes',
$attribute->getId(), $attribute->getId(),
$attribute $attribute
->setAttribute('status', 'failed') ->setAttribute('status', 'failed')
->setAttribute('error', 'Internal Error') ->setAttribute('error', '')
); );
} finally { } finally {
$target = Realtime::fromPayload( $target = Realtime::fromPayload(
@ -169,10 +169,10 @@ class DatabaseV1 extends Worker
// - stuck: attribute was available but cannot be removed // - stuck: attribute was available but cannot be removed
try { try {
if ($status !== 'failed' && !$dbForProject->deleteAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key)) { if ($status !== 'failed' && !$dbForProject->deleteAttribute('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key)) {
throw new Exception('Failed to delete Attribute'); throw new DatabaseException('Failed to delete Attribute');
} }
$dbForProject->deleteDocument('attributes', $attribute->getId()); $dbForProject->deleteDocument('attributes', $attribute->getId());
} catch (Exception $e) { } catch (DatabaseException $e) {
Console::error($e->getMessage()); Console::error($e->getMessage());
$dbForProject->updateDocument( $dbForProject->updateDocument(
'attributes', 'attributes',
@ -181,14 +181,13 @@ class DatabaseV1 extends Worker
->setAttribute('status', 'stuck') ->setAttribute('status', 'stuck')
->setAttribute('error', $e->getMessage()) ->setAttribute('error', $e->getMessage())
); );
} catch (\Throwable $th) { } catch (Exception $e) {
Console::error('Internal Error');
$dbForProject->updateDocument( $dbForProject->updateDocument(
'attributes', 'attributes',
$attribute->getId(), $attribute->getId(),
$attribute $attribute
->setAttribute('status', 'stuck') ->setAttribute('status', 'stuck')
->setAttribute('error', 'Internal Error') ->setAttribute('error', '')
); );
} finally { } finally {
$target = Realtime::fromPayload( $target = Realtime::fromPayload(
@ -294,10 +293,10 @@ class DatabaseV1 extends Worker
try { try {
if (!$dbForProject->createIndex('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key, $type, $attributes, $lengths, $orders)) { if (!$dbForProject->createIndex('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key, $type, $attributes, $lengths, $orders)) {
throw new Exception('Failed to create Index'); throw new DatabaseException('Failed to create Index');
} }
$dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'available')); $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'available'));
} catch (Exception $e) { } catch (DatabaseException $e) {
Console::error($e->getMessage()); Console::error($e->getMessage());
$dbForProject->updateDocument( $dbForProject->updateDocument(
'indexes', 'indexes',
@ -306,14 +305,13 @@ class DatabaseV1 extends Worker
->setAttribute('status', 'failed') ->setAttribute('status', 'failed')
->setAttribute('error', $e->getMessage()) ->setAttribute('error', $e->getMessage())
); );
} catch (\Throwable $th) { } catch (Exception $e) {
Console::Error('Internal Error');
$dbForProject->updateDocument( $dbForProject->updateDocument(
'indexes', 'indexes',
$index->getId(), $index->getId(),
$index $index
->setAttribute('status', 'failed') ->setAttribute('status', 'failed')
->setAttribute('error', 'Internal Error') ->setAttribute('error', '')
); );
} finally { } finally {
$target = Realtime::fromPayload( $target = Realtime::fromPayload(
@ -362,10 +360,10 @@ class DatabaseV1 extends Worker
try { try {
if ($status !== 'failed' && !$dbForProject->deleteIndex('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key)) { if ($status !== 'failed' && !$dbForProject->deleteIndex('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId(), $key)) {
throw new Exception('Failed to delete index'); throw new DatabaseException('Failed to delete index');
} }
$dbForProject->deleteDocument('indexes', $index->getId()); $dbForProject->deleteDocument('indexes', $index->getId());
} catch (Exception $e) { } catch (DatabaseException $e) {
Console::error($e->getMessage()); Console::error($e->getMessage());
$dbForProject->updateDocument( $dbForProject->updateDocument(
'indexes', 'indexes',
@ -374,14 +372,13 @@ class DatabaseV1 extends Worker
->setAttribute('status', 'stuck') ->setAttribute('status', 'stuck')
->setAttribute('error', $e->getMessage()) ->setAttribute('error', $e->getMessage())
); );
} catch (\Throwable $th) { } catch (Exception $e) {
Console::error('Internal Error');
$dbForProject->updateDocument( $dbForProject->updateDocument(
'indexes', 'indexes',
$index->getId(), $index->getId(),
$index $index
->setAttribute('status', 'stuck') ->setAttribute('status', 'stuck')
->setAttribute('error', 'Internal Error') ->setAttribute('error', '')
); );
} finally { } finally {
$target = Realtime::fromPayload( $target = Realtime::fromPayload(