Jelajahi Sumber

Merge pull request #2255 from visuddhinanda/development

rabbitmq timeout =15
visuddhinanda 1 tahun lalu
induk
melakukan
818bae9f5b
2 mengubah file dengan 13 tambahan dan 5 penghapusan
  1. 3 3
      api-v8/app/Console/Commands/MqDiscussion.php
  2. 10 2
      api-v8/app/Http/Api/Mq.php

+ 3 - 3
api-v8/app/Console/Commands/MqDiscussion.php

@@ -199,8 +199,8 @@ class MqDiscussion extends Command
                         $sendTo[] = $term->term;
                         //作者
                         $editor = UserApi::getById($term->editor_id);
-                        if ($editor['id'] !== 0 && !in_array($editor['uid'], $sendTo)) {
-                            $sendTo[] = $editor['uid'];
+                        if ($editor['id'] !== 0 && !in_array($editor['id'], $sendTo)) {
+                            $sendTo[] = $editor['id'];
                         }
                         $this->notification(
                             $message->editor->id,
@@ -231,7 +231,7 @@ class MqDiscussion extends Command
 
     private function WebHook($msgParam, $type, $resId)
     {
-        $rootId = UserApi::getById(0)['uid'];
+        $rootId = UserApi::getById(0)['id'];
         $articleTitle = "webhook://discussion/{$type}/zh-hans";
         $tpl = Article::where('owner', $rootId)
             ->where('title', $articleTitle)

+ 10 - 2
api-v8/app/Http/Api/Mq.php

@@ -165,11 +165,19 @@ class Mq
         };
 
         register_shutdown_function($shutdown, $channel, $connection);
+
+        $timeout = 15;
+        $deadline = time() + $timeout;
         // Loop as long as the channel has callbacks registered
         while ($channel->is_consuming()) {
-            $channel->wait(null, true);
+            try {
+                $channel->wait(null, false, $deadline - time());
+            } catch (\Throwable $th) {
+                //throw $th;
+                Log::error('rabbitmq timeout');
+            }
+
             // do something else
-            usleep(300000);
         }
     }
 }