60812aba91
Standardised rich name for Files * tests
65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package documentstore
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
|
|
docinitrunner "queryorchestration/api/docInitRunner"
|
|
doctextprocessrunner "queryorchestration/api/docTextProcessRunner"
|
|
"queryorchestration/internal/serviceconfig/objectstore"
|
|
"queryorchestration/internal/serviceconfig/queue"
|
|
)
|
|
|
|
type Params struct {
|
|
Event EventS3
|
|
Key string
|
|
Bucket string
|
|
Hash string
|
|
}
|
|
|
|
type EventS3 string
|
|
|
|
const (
|
|
EventS3ObjectCreatedPut = "ObjectCreated:Put"
|
|
)
|
|
|
|
func (s *Service) Process(ctx context.Context, params Params) error {
|
|
if !s.isSupportedEvent(params.Event) {
|
|
slog.Warn("unsupported event", "name", params.Event)
|
|
return nil
|
|
}
|
|
|
|
key, err := objectstore.ParseBucketKey(params.Key)
|
|
if err != nil {
|
|
slog.Error("unable to parse key", "key", params.Key)
|
|
return nil
|
|
}
|
|
|
|
queueParams := &queue.SendParams{}
|
|
switch key.Location {
|
|
case objectstore.Import:
|
|
queueParams.QueueURL = s.cfg.GetDocInitURL()
|
|
queueParams.Body = docinitrunner.Body{
|
|
Bucket: params.Bucket,
|
|
Key: params.Key,
|
|
Hash: params.Hash,
|
|
}
|
|
case objectstore.TextTextract:
|
|
queueParams.QueueURL = s.cfg.GetDocumentTextProcessURL()
|
|
queueParams.Body = doctextprocessrunner.Body{
|
|
Bucket: params.Bucket,
|
|
Key: params.Key,
|
|
Hash: params.Hash,
|
|
}
|
|
default:
|
|
slog.Info("unsupported key", "key", params.Key)
|
|
return nil
|
|
}
|
|
|
|
return s.cfg.SendToQueue(ctx, queueParams)
|
|
}
|
|
|
|
func (s *Service) isSupportedEvent(name EventS3) bool {
|
|
return name == EventS3ObjectCreatedPut
|
|
}
|