From 478e83a4bfe0684bce91d8ddbe3fdab86e9b407f Mon Sep 17 00:00:00 2001 From: shimon Date: Tue, 30 May 2023 11:53:52 +0300 Subject: [PATCH] Messaging --- app/worker.php | 15 ++++++--------- src/Appwrite/Platform/Workers/Audits.php | 5 +++++ src/Appwrite/Platform/Workers/Messaging.php | 16 +++++++++------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/worker.php b/app/worker.php index 3cd7c8ebe..1108341b9 100644 --- a/app/worker.php +++ b/app/worker.php @@ -221,23 +221,20 @@ Server::setResource('getBuildsDevice', function (string $projectId) { $pools = $register->get('pools'); $platform = new Appwrite(); -$_args = (!empty($args) || !isset($_SERVER['argv']) ? $args : $_SERVER['argv']); +$args = $_SERVER['argv']; -if (isset($_args[0])) { - $workerName = end($_args); +if (isset($args[0])) { + $workerName = end($args); } else { - throw new Exception('Missing command'); + throw new Exception('Missing worker name'); } $platform->init(Service::TYPE_WORKER, [ - 'queue' => App::getEnv('QUEUE'), - 'workerNumber' => swoole_cpu_num() * intval(App::getEnv('_APP_WORKER_PER_CORE', 6)), + 'workersNumber' => swoole_cpu_num() * intval(App::getEnv('_APP_WORKER_PER_CORE', 6)), 'connection' => $pools->get('queue')->pop()->getResource(), - 'name' => $workerName, + 'workerName' => $workerName, ]); - - $worker = $platform->getWorker(); $worker diff --git a/src/Appwrite/Platform/Workers/Audits.php b/src/Appwrite/Platform/Workers/Audits.php index 45929bf71..cbcb4a2c4 100644 --- a/src/Appwrite/Platform/Workers/Audits.php +++ b/src/Appwrite/Platform/Workers/Audits.php @@ -3,6 +3,7 @@ namespace Appwrite\Platform\Workers; use Exception; +use Utopia\App; use Utopia\Audit\Audit; use Utopia\Database\Database; use Utopia\Database\Document; @@ -11,6 +12,8 @@ use Utopia\Queue\Message; class Audits extends Action { + protected static array $init; + public static function getName(): string { return 'audits'; @@ -25,8 +28,10 @@ class Audits extends Action ->callback(fn ($message, $dbForProject) => $this->action($message, $dbForProject)); } + public function action(Message $message, $dbForProject): void { + $payload = $message->getPayload() ?? []; if (empty($payload)) { diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index a58f8b171..a75befaff 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -18,10 +18,10 @@ use Utopia\Queue\Message; class Messaging extends Action { - private ?DSN $dsn; - private string $user; - private string $secret; - private string $provider; + private ?DSN $dsn = null; + private string $user = ''; + private string $secret = ''; + private string $provider = ''; public static function getName(): string { @@ -31,9 +31,11 @@ class Messaging extends Action public function __construct() { $this->provider = App::getEnv('_APP_SMS_PROVIDER', ''); - $this->dsn = !empty($this->provider) ? new DSN($this->provider) : null; - $this->user = !empty($this->provider) ? $this->dsn->getUser() : ''; - $this->secret = !empty($this->provider) ? $this->dsn->getPassword() : ''; + if (!empty($this->provider)) { + $this->dsn = new DSN($this->provider); + $this->user = $this->dsn->getUser(); + $this->secret = $this->dsn->getPassword(); + } $this ->desc('Messaging worker')