1d49313a9f
Feature/standardisefilepath * baseprocessing * generalstructure
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package doctextprocessrunner
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
|
|
documenttext "queryorchestration/internal/document/text"
|
|
"queryorchestration/internal/serviceconfig/objectstore"
|
|
|
|
"github.com/go-playground/validator/v10"
|
|
)
|
|
|
|
const Name = "docTextProcessRunner"
|
|
|
|
type Services struct {
|
|
Text *documenttext.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"`
|
|
ClientID string `json:"clientId" 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 true
|
|
}
|
|
|
|
err = s.svc.Text.Process(ctx, &documenttext.ProcessParams{
|
|
Bucket: body.Bucket,
|
|
Key: key,
|
|
Hash: body.Hash,
|
|
ClientID: body.ClientID,
|
|
})
|
|
if err != nil {
|
|
slog.Error("unable to process", "bucket", body.Bucket, "key", body.Key, "hash", body.Hash, "error", err)
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|