MCPcopy Index your code
hub / github.com/coder/coder / setChatWaiting

Method setChatWaiting

coderd/x/chatd/chatd.go:3860–3892  ·  view source on GitHub ↗
(ctx context.Context, chatID uuid.UUID)

Source from the content-addressed store, hash-verified

3858}
3859
3860func (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
3894func insertChatMessageWithStore(
3895 ctx context.Context,

Callers 2

SendMessageMethod · 0.95
InterruptChatMethod · 0.95

Calls 6

publishStatusMethod · 0.95
InTxMethod · 0.65
GetChatByIDForUpdateMethod · 0.65
UpdateChatStatusMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected