Files
query-orchestration/api/docInitRunner/runner.go
T

52 lines
957 B
Go
Raw Normal View History

package docinitrunner
2024-12-18 18:54:48 +00:00
import (
"context"
"log/slog"
2025-03-05 12:05:46 +00:00
documentinit "queryorchestration/internal/document/init"
"queryorchestration/internal/serviceconfig/objectstore"
2024-12-18 18:54:48 +00:00
)
const Name = "docInitRunner"
type Services struct {
Document *documentinit.Service
}
type Runner struct {
svc *Services
2024-12-18 18:54:48 +00:00
}
func New(svc *Services) Runner {
return Runner{
svc: svc,
2024-12-18 18:54:48 +00:00
}
}
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
2024-12-18 18:54:48 +00:00
}
slog.Debug("created document", "id", id)
2024-12-18 18:54:48 +00:00
return true
}