Разрешите отправку сообщения во время публикации вложения
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"messenger/internal/attachment"
|
||||
"messenger/internal/chat"
|
||||
"messenger/internal/platform/apperr"
|
||||
"messenger/internal/platform/postgres"
|
||||
@@ -209,12 +210,13 @@ func validateAttachments(ctx context.Context, tx pgx.Tx, chatID uuid.UUID, ids [
|
||||
return apperr.NotFound("attachment not found")
|
||||
}
|
||||
// A separate statement sees the latest committed transition after a lock wait.
|
||||
// Every referenced attachment must have a current job.
|
||||
rows, err = tx.Query(ctx, `SELECT status FROM attachment_states WHERE id=ANY($1::uuid[]) ORDER BY id FOR SHARE`, ids)
|
||||
// Terminal failures take FOR UPDATE on the job or file. KEY SHARE orders
|
||||
// validation with those transitions while allowing an outbox publish in flight.
|
||||
rows, err = tx.Query(ctx, `SELECT status FROM attachment_states WHERE id=ANY($1::uuid[]) ORDER BY id FOR KEY SHARE`, ids)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
states, err := pgx.CollectRows(rows, pgx.RowTo[string])
|
||||
states, err := pgx.CollectRows(rows, pgx.RowTo[attachment.FileStatus])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -223,7 +225,7 @@ func validateAttachments(ctx context.Context, tx pgx.Tx, chatID uuid.UUID, ids [
|
||||
}
|
||||
for _, state := range states {
|
||||
switch state {
|
||||
case "queued", "processing", "ready":
|
||||
case attachment.FileQueued, attachment.FileProcessing, attachment.FileReady:
|
||||
default:
|
||||
return apperr.Conflict("attachment processing failed")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user