Просмотр исходного кода

把RabbitMQService 放到使用之前

visuddhinanda 9 месяцев назад
Родитель
Сommit
29836bda0e

+ 2 - 2
api-v8/app/Console/Commands/RabbitMQWorker.php

@@ -31,7 +31,7 @@ class RabbitMQWorker extends Command
     private $timeout = 15;
     private $job = null;
 
-    public function handle(RabbitMQService $consume)
+    public function handle()
     {
         if (\App\Tools\Tools::isStop()) {
             return 0;
@@ -50,7 +50,7 @@ class RabbitMQWorker extends Command
         $this->info("队列: {$this->queueName}");
         $this->info("最大循环次数: {$this->maxLoopCount}");
         $this->info("重试次数: {$this->queueConfig['retry_times']}");
-
+        $consume = app(RabbitMQService::class);
         try {
             $consume->setupQueue($this->queueName);
             $this->channel = $consume->getChannel();

+ 2 - 2
api-v8/app/Console/Commands/TestAiTask.php

@@ -38,10 +38,10 @@ class TestAiTask extends Command
      *
      * @return int
      */
-    public function handle(AiTranslateService $ai)
+    public function handle()
     {
         $taskId = $this->argument('id');
-
+        $ai = app(AiTranslateService::class);
         $params = $ai->makeByTask($taskId, !$this->option('test'));
         var_dump($params);
         var_dump($this->option('test'));

+ 3 - 2
api-v8/app/Console/Commands/TestMq.php

@@ -33,9 +33,8 @@ class TestMq extends Command
      *
      * @return void
      */
-    public function __construct(RabbitMQService $publish)
+    public function __construct()
     {
-        $this->publish = $publish;
         parent::__construct();
     }
 
@@ -49,6 +48,8 @@ class TestMq extends Command
         if (\App\Tools\Tools::isStop()) {
             return 0;
         }
+        $publish = app(RabbitMQService::class);
+        $this->publish = $publish;
         $this->publish->publishMessage('ai_translate', ['text' => 'hello']);
 
         Mq::publish('hello', ['hello world']);

+ 2 - 2
api-v8/app/Http/Controllers/TaskStatusController.php

@@ -79,7 +79,7 @@ class TaskStatusController extends Controller
      * @param  \App\Models\Task  $task
      * @return \Illuminate\Http\Response
      */
-    public function update(Request $request, string $id, AiTranslateService $ai)
+    public function update(Request $request, string $id)
     {
         //
         $task = Task::findOrFail($id);
@@ -189,7 +189,7 @@ class TaskStatusController extends Controller
             $aiAssistant = AiModel::whereIn('uid', $taskAssignee)->first();
             if ($aiAssistant) {
                 try {
-
+                    $ai = app(AiTranslateService::class);
                     $params = $ai->makeByTask($taskId, $aiAssistant->uid);
                     Log::debug('ai task', ['message' => count($params)]);
                     $aiTask = Task::find($taskId);

+ 2 - 2
api-v8/app/Services/AiTranslateService.php

@@ -31,9 +31,9 @@ class AiTranslateService
     private $apiTimeout = 100;
     private $llmTimeout = 300;
     private $taskTopicId;
-    public function __construct(RabbitMQService $mq)
+    public function __construct()
     {
-        $this->mq = $mq;
+        $this->mq = app(RabbitMQService::class);
     }
 
     /**