Files
query-orchestration/internal/document/store/process.go
T

57 lines
1.2 KiB
Go
Raw Normal View History

package documentstore
import (
"context"
"log/slog"
docinitrunner "queryorchestration/api/docInitRunner"
"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,
}
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
}