2025-02-03 17:30:50 +00:00
|
|
|
package docinitrunner
|
2024-12-18 18:54:48 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2025-02-06 15:00:26 +00:00
|
|
|
"log/slog"
|
2025-03-05 12:05:46 +00:00
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
documentinit "queryorchestration/internal/document/init"
|
2025-04-03 19:17:24 +00:00
|
|
|
"queryorchestration/internal/serviceconfig/objectstore"
|
2024-12-18 18:54:48 +00:00
|
|
|
|
2024-12-23 16:49:53 +00:00
|
|
|
"github.com/go-playground/validator/v10"
|
2024-12-18 18:54:48 +00:00
|
|
|
)
|
|
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
const Name = "docInitRunner"
|
|
|
|
|
|
2025-01-24 16:12:25 +00:00
|
|
|
type Services struct {
|
2025-02-03 17:30:50 +00:00
|
|
|
Document *documentinit.Service
|
2025-01-24 16:12:25 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
type Runner struct {
|
2024-12-23 16:49:53 +00:00
|
|
|
validator *validator.Validate
|
2025-01-24 16:12:25 +00:00
|
|
|
svc *Services
|
2024-12-18 18:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
func New(validator *validator.Validate, svc *Services) Runner {
|
|
|
|
|
return Runner{
|
2024-12-23 16:49:53 +00:00
|
|
|
validator: validator,
|
2025-01-24 16:12:25 +00:00
|
|
|
svc: svc,
|
2024-12-18 18:54:48 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-02 18:50:03 +00:00
|
|
|
type Body struct {
|
2025-04-03 19:17:24 +00:00
|
|
|
Bucket string `json:"bucket" validate:"required"`
|
|
|
|
|
Key string `json:"key" validate:"required"`
|
|
|
|
|
Hash string `json:"hash" validate:"required"`
|
2025-03-05 19:49:03 +00:00
|
|
|
}
|
|
|
|
|
|
2025-04-02 18:50:03 +00:00
|
|
|
func (s Runner) Process(ctx context.Context, body Body) bool {
|
2025-04-03 19:17:24 +00:00
|
|
|
key, err := objectstore.ParseBucketKey(body.Key)
|
|
|
|
|
if err != nil {
|
|
|
|
|
slog.Error("unable to parse key", "key", body.Key)
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-02 18:50:03 +00:00
|
|
|
id, err := s.svc.Document.Create(ctx, &documentinit.Create{
|
2025-04-03 19:17:24 +00:00
|
|
|
Key: key,
|
|
|
|
|
Bucket: body.Bucket,
|
|
|
|
|
Hash: body.Hash,
|
2025-03-05 19:49:03 +00:00
|
|
|
})
|
|
|
|
|
if err != nil {
|
2025-04-02 18:50:03 +00:00
|
|
|
return false
|
2024-12-18 18:54:48 +00:00
|
|
|
}
|
2025-04-02 18:50:03 +00:00
|
|
|
slog.Debug("created document", "id", id)
|
2024-12-18 18:54:48 +00:00
|
|
|
|
2025-04-02 18:50:03 +00:00
|
|
|
return true
|
2025-03-05 19:49:03 +00:00
|
|
|
}
|