lab5: асинхронная очередь, worker и идемпотентный pipeline

API принимает 202 после durable staging и TX intent (job+outbox); отдельные relay и worker публикуют/обрабатывают задания с publisher confirm, lease, retry/backoff, DLQ и replay. Добавлены версии pipeline, варианты thumbnail/crop/optimized, presign в verified staging, status-aware sweeper и admission control.
This commit is contained in:
Vladislav Kunetskiy
2026-10-30 22:36:52 +03:00
parent 6c5ba026f1
commit 4bdcac3dfa
95 changed files with 8466 additions and 764 deletions
+42 -6
View File
@@ -56,11 +56,14 @@ func (h *Handler) DownloadAttachment(
ctx context.Context,
params oas.DownloadAttachmentParams,
) (oas.DownloadAttachmentRes, error) {
if variant, ok := params.Variant.Get(); ok && variant != oas.DownloadAttachmentVariantOriginal {
return nil, fmt.Errorf("%w: variant %q is not available", domain.ErrNotFound, variant)
variant := domain.VariantOriginal
if requested, ok := params.Variant.Get(); ok {
variant = domain.VariantName(requested)
}
attachment, body, err := h.attachments.Open(ctx, caller(ctx), params.AttachmentID)
attachment, metadata, body, err := h.attachments.OpenVariant(
ctx, caller(ctx), params.AttachmentID, variant,
)
if err != nil {
return nil, err
}
@@ -73,7 +76,7 @@ func (h *Handler) DownloadAttachment(
requestID := oas.NewOptString(requestIDFromContext(ctx))
reader := closeOnEOF{ReadCloser: body}
switch attachment.ContentType {
switch metadata.ContentType {
case "image/png":
return &oas.DownloadAttachmentOKImagePNGHeaders{
XRequestID: requestID,
@@ -84,6 +87,11 @@ func (h *Handler) DownloadAttachment(
XRequestID: requestID,
Response: oas.DownloadAttachmentOKImageJpeg{Data: reader},
}, nil
case "image/webp":
return &oas.DownloadAttachmentOKImageWEBPHeaders{
XRequestID: requestID,
Response: oas.DownloadAttachmentOKImageWEBP{Data: reader},
}, nil
default:
_ = body.Close()
@@ -110,11 +118,11 @@ func attachmentResponse(attachment domain.Attachment) oas.Attachment {
Filename: attachment.Filename,
SizeBytes: int(attachment.SizeBytes),
SHA256: attachment.SHA256,
Status: oas.AttachmentStatusReady,
Variants: []oas.Variant{},
Status: attachmentStatus(attachment.Status),
ErrorCode: oas.NilString{Null: true},
CreatedAt: attachment.CreatedAt,
UpdatedAt: attachment.UpdatedAt,
Variants: make([]oas.Variant, 0, len(attachment.Variants)),
}
switch attachment.ContentType {
@@ -130,9 +138,37 @@ func attachmentResponse(attachment domain.Attachment) oas.Attachment {
response.ErrorCode = oas.NilString{Value: *attachment.ErrorCode}
}
for _, variant := range attachment.Variants {
response.Variants = append(response.Variants, oas.Variant{
Name: oas.VariantName(variant.Name),
ContentType: oas.VariantContentType(variant.ContentType),
SizeBytes: int(variant.SizeBytes),
Width: variant.Width,
Height: variant.Height,
SHA256: variant.SHA256,
})
}
return response
}
func attachmentStatus(status domain.AttachmentStatus) oas.AttachmentStatus {
switch status {
case domain.AttachmentQueued:
return oas.AttachmentStatusQueued
case domain.AttachmentProcessing:
return oas.AttachmentStatusProcessing
case domain.AttachmentReady:
return oas.AttachmentStatusReady
case domain.AttachmentFailed:
return oas.AttachmentStatusFailed
default:
// Pending is internal and never reaches the transport; map it to the
// closest public state rather than inventing a new enum value.
return oas.AttachmentStatusQueued
}
}
type closeOnEOF struct {
io.ReadCloser
}