dialogId = $dialogId; $this->command = $command; $this->userId = $userId; $this->pendingMsgId = $pendingMsgId; } public function start() { $dialog = WebSocketDialog::find($this->dialogId); if (!$dialog) { // 对话不存在,释放锁 Cache::forget("ai_dialog_command:{$this->dialogId}"); return; } try { match ($this->command) { 'analyze' => AiDialogCommand::analyze($dialog, $this->userId, $this->pendingMsgId), 'summarize' => AiDialogCommand::summarize($dialog, $this->userId, $this->pendingMsgId), default => null, }; } catch (\Throwable $e) { // 异常时释放锁,避免死锁 Cache::forget("ai_dialog_command:{$this->dialogId}"); throw $e; } } public function end() { } }