Files
query-orchestration/api/docInitRunner/runner.go
T
Michael McGuinness 60812aba91 Merged in feature/richname (pull request #112)
Standardised rich name for Files

* tests
2025-04-03 19:17:24 +00:00

56 lines
1.1 KiB
Go

package docinitrunner
import (
"context"
"log/slog"
documentinit "queryorchestration/internal/document/init"
"queryorchestration/internal/serviceconfig/objectstore"
"github.com/go-playground/validator/v10"
)
const Name = "docInitRunner"
type Services struct {
Document *documentinit.Service
}
type Runner struct {
validator *validator.Validate
svc *Services
}
func New(validator *validator.Validate, svc *Services) Runner {
return Runner{
validator: validator,
svc: svc,
}
}
type Body struct {
Bucket string `json:"bucket" validate:"required"`
Key string `json:"key" validate:"required"`
Hash string `json:"hash" validate:"required"`
}
func (s Runner) Process(ctx context.Context, body Body) bool {
key, err := objectstore.ParseBucketKey(body.Key)
if err != nil {
slog.Error("unable to parse key", "key", body.Key)
return false
}
id, err := s.svc.Document.Create(ctx, &documentinit.Create{
Key: key,
Bucket: body.Bucket,
Hash: body.Hash,
})
if err != nil {
return false
}
slog.Debug("created document", "id", id)
return true
}