(ctx context.Context, chatID uuid.UUID)
| 3858 | } |
| 3859 | |
| 3860 | func (p *Server) setChatWaiting(ctx context.Context, chatID uuid.UUID) (database.Chat, error) { |
| 3861 | var updatedChat database.Chat |
| 3862 | err := p.db.InTx(func(tx database.Store) error { |
| 3863 | locked, lockErr := tx.GetChatByIDForUpdate(ctx, chatID) |
| 3864 | if lockErr != nil { |
| 3865 | return xerrors.Errorf("lock chat for waiting: %w", lockErr) |
| 3866 | } |
| 3867 | // If the chat has already transitioned to pending (e.g. |
| 3868 | // SendMessage with interrupt behavior), don't overwrite |
| 3869 | // it — the pending status takes priority so the new |
| 3870 | // message gets processed. |
| 3871 | if locked.Status == database.ChatStatusPending { |
| 3872 | updatedChat = locked |
| 3873 | return nil |
| 3874 | } |
| 3875 | var updateErr error |
| 3876 | updatedChat, updateErr = tx.UpdateChatStatus(ctx, database.UpdateChatStatusParams{ |
| 3877 | ID: chatID, |
| 3878 | Status: database.ChatStatusWaiting, |
| 3879 | WorkerID: uuid.NullUUID{}, |
| 3880 | StartedAt: sql.NullTime{}, |
| 3881 | HeartbeatAt: sql.NullTime{}, |
| 3882 | LastError: pqtype.NullRawMessage{}, |
| 3883 | }) |
| 3884 | return updateErr |
| 3885 | }, nil) |
| 3886 | if err != nil { |
| 3887 | return database.Chat{}, err |
| 3888 | } |
| 3889 | p.publishStatus(chatID, updatedChat.Status, updatedChat.WorkerID) |
| 3890 | p.publishChatPubsubEvent(updatedChat, codersdk.ChatWatchEventKindStatusChange, nil) |
| 3891 | return updatedChat, nil |
| 3892 | } |
| 3893 | |
| 3894 | func insertChatMessageWithStore( |
| 3895 | ctx context.Context, |
no test coverage detected