Wire the artifact storage foundation to HTTP.
- PUT /tasks/{id}/artifacts/{filename}: a worker streams a partial result;
the coordinator verifies lease ownership (foreign worker → 409), streams
the bytes to blob storage while hashing, and records the metadata. An
orphaned blob from a failed metadata insert is cleaned up.
- GET /artifacts/{id}/download: streams an artifact back with its content
type, length, and checksum.
- Ownership is read with a new non-locking TaskRepository.Get, so no row lock
is held across a long upload. Identity travels in X-Worker-ID / X-Task-Attempt
headers per the contract; upload/download bypass the short request timeout.
- docker-compose mounts ./data for durable artifact storage; smoke and
requests.http exercise an upload → foreign-409 → download round-trip.
70 lines
1.2 KiB
Go
70 lines
1.2 KiB
Go
package usecase
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// Use-case boundary types. Adapters map their wire formats onto these, so the
|
|
// HTTP shape can change without touching business code.
|
|
|
|
type CreateJobInput struct {
|
|
Workload string
|
|
InputURI string
|
|
Parameters map[string]any
|
|
Chunks []ChunkInput
|
|
}
|
|
|
|
type ChunkInput struct {
|
|
ChunkIndex int
|
|
Workload string
|
|
InputURI string
|
|
InputSHA256 string
|
|
Parameters map[string]any
|
|
MaxAttempts int
|
|
}
|
|
|
|
type RegisterWorkerInput struct {
|
|
Name string
|
|
Capabilities []string
|
|
}
|
|
|
|
type ClaimTaskInput struct {
|
|
WorkerID string
|
|
Workloads []string
|
|
}
|
|
|
|
type RenewLeaseInput struct {
|
|
TaskID uuid.UUID
|
|
WorkerID string
|
|
Attempt int
|
|
}
|
|
|
|
type CompleteTaskInput struct {
|
|
TaskID uuid.UUID
|
|
WorkerID string
|
|
Attempt int
|
|
ResultURI string
|
|
ResultSHA256 string
|
|
Metrics map[string]any
|
|
}
|
|
|
|
type UploadArtifactInput struct {
|
|
TaskID uuid.UUID
|
|
WorkerID string
|
|
Attempt int
|
|
Filename string
|
|
ContentType string
|
|
Body io.Reader
|
|
}
|
|
|
|
type FailTaskInput struct {
|
|
TaskID uuid.UUID
|
|
WorkerID string
|
|
Attempt int
|
|
ErrorCode string
|
|
ErrorMessage string
|
|
Retryable bool
|
|
}
|