diff --git a/app/worker.php b/app/worker.php index 4de14c396..7713f6c55 100644 --- a/app/worker.php +++ b/app/worker.php @@ -247,7 +247,7 @@ $worker throw $error; } - if ($logger && ($error->getCode() >= 500 || $error->getCode() === 0)) { + if ($logger) { $log->setNamespace("appwrite-worker"); $log->setServer(\gethostname()); $log->setVersion($version); diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index d2b5b9f48..bf4c75e69 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -4,7 +4,6 @@ namespace Appwrite\Platform\Workers; use Appwrite\Event\Event; use Appwrite\Event\Func; -use Appwrite\Event\Usage; use Appwrite\Messaging\Adapter\Realtime; use Appwrite\Usage\Stats; use Appwrite\Utopia\Response\Model\Deployment; @@ -28,7 +27,6 @@ use Utopia\Logger\Log; use Utopia\Platform\Action; use Utopia\Queue\Message; use Utopia\Storage\Device\Local; -use Utopia\Storage\Storage; use Utopia\VCS\Adapter\Git\GitHub; class Builds extends Action @@ -514,10 +512,7 @@ class Builds extends Action $build->setAttribute('endTime', $endTime); $build->setAttribute('duration', \intval(\ceil($durationEnd - $durationStart))); $build->setAttribute('status', 'failed'); - $build->setAttribute('logs', $th->getMessage()); - Console::error($th->getMessage()); - Console::error($th->getFile() . ':' . $th->getLine()); - Console::error($th->getTraceAsString()); + $build->setAttribute('logs', $th->getMessage() . "\n" . $th->getFile() . ':' . $th->getLine() . "\n" . $th->getTraceAsString()); if ($isVcsEnabled) { $this->runGitAction('failed', $github, $providerCommitHash, $owner, $repositoryName, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole); diff --git a/src/Appwrite/Platform/Workers/Databases.php b/src/Appwrite/Platform/Workers/Databases.php index c397d744d..4ef939d90 100644 --- a/src/Appwrite/Platform/Workers/Databases.php +++ b/src/Appwrite/Platform/Workers/Databases.php @@ -4,7 +4,6 @@ namespace Appwrite\Platform\Workers; use Appwrite\Event\Event; use Appwrite\Messaging\Adapter\Realtime; -use Appwrite\Utopia\Response\Model\Platform; use Exception; use Utopia\Audit\Audit; use Utopia\CLI\Console; @@ -72,14 +71,14 @@ class Databases extends Action $log->addTag('databaseId', $database->getId()); - match (strval($type)) { + match (\strval($type)) { DATABASE_TYPE_DELETE_DATABASE => $this->deleteDatabase($database, $project, $dbForProject), DATABASE_TYPE_DELETE_COLLECTION => $this->deleteCollection($database, $collection, $project, $dbForProject), DATABASE_TYPE_CREATE_ATTRIBUTE => $this->createAttribute($database, $collection, $document, $project, $dbForConsole, $dbForProject), DATABASE_TYPE_DELETE_ATTRIBUTE => $this->deleteAttribute($database, $collection, $document, $project, $dbForConsole, $dbForProject), DATABASE_TYPE_CREATE_INDEX => $this->createIndex($database, $collection, $document, $project, $dbForConsole, $dbForProject), DATABASE_TYPE_DELETE_INDEX => $this->deleteIndex($database, $collection, $document, $project, $dbForConsole, $dbForProject), - default => Console::error('No database operation for type: ' . $type), + default => throw new \Exception('No database operation for type: ' . \strval($type)), }; } @@ -167,6 +166,7 @@ class Databases extends Action $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'available')); } catch (\Exception $e) { + // TODO: Send non DatabaseExceptions to Sentry Console::error($e->getMessage()); if ($e instanceof DatabaseException) { @@ -176,6 +176,7 @@ class Databases extends Action } } + $dbForProject->updateDocument( 'attributes', $attribute->getId(), @@ -269,6 +270,7 @@ class Databases extends Action $dbForProject->deleteDocument('attributes', $relatedAttribute->getId()); } } catch (\Exception $e) { + // TODO: Send non DatabaseExceptions to Sentry Console::error($e->getMessage()); if ($e instanceof DatabaseException) { @@ -396,6 +398,7 @@ class Databases extends Action } $dbForProject->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'available')); } catch (\Exception $e) { + // TODO: Send non DatabaseExceptions to Sentry Console::error($e->getMessage()); if ($e instanceof DatabaseException) { @@ -453,6 +456,7 @@ class Databases extends Action $dbForProject->deleteDocument('indexes', $index->getId()); $index->setAttribute('status', 'deleted'); } catch (\Exception $e) { + // TODO: Send non DatabaseExceptions to Sentry Console::error($e->getMessage()); if ($e instanceof DatabaseException) { @@ -589,7 +593,7 @@ class Databases extends Action $callback($document); } } else { - Console::error('Failed to delete document: ' . $document->getId()); + Console::warning('Failed to delete document: ' . $document->getId()); } $count++; } diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 2affc1f77..c718a5a3b 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -73,7 +73,7 @@ class Deletes extends Action $log->addTag('projectId', $project->getId()); $log->addTag('type', $type); - switch (strval($type)) { + switch (\strval($type)) { case DELETE_TYPE_DOCUMENT: switch ($document->getCollection()) { case DELETE_TYPE_DATABASES: @@ -159,7 +159,7 @@ class Deletes extends Action $this->deleteTopic($project, $getProjectDB, $document); break; default: - Console::error('No delete operation for type: ' . $type); + throw new \Exception('No delete operation for type: ' . \strval($type)); break; } } diff --git a/src/Appwrite/Platform/Workers/Mails.php b/src/Appwrite/Platform/Workers/Mails.php index ea9b77a8c..7b4bbbebc 100644 --- a/src/Appwrite/Platform/Workers/Mails.php +++ b/src/Appwrite/Platform/Workers/Mails.php @@ -7,7 +7,6 @@ use Exception; use PHPMailer\PHPMailer\PHPMailer; use Swoole\Runtime; use Utopia\App; -use Utopia\CLI\Console; use Utopia\Logger\Log; use Utopia\Platform\Action; use Utopia\Queue\Message; @@ -53,8 +52,7 @@ class Mails extends Action $smtp = $payload['smtp']; if (empty($smtp) && empty(App::getEnv('_APP_SMTP_HOST'))) { - Console::info('Skipped mail processing. No SMTP configuration has been set.'); - return; + throw new Exception('Skipped mail processing. No SMTP configuration has been set.'); } $log->addTag('type', empty($smtp) ? 'cloud' : 'smtp');