Merged in feature/standardisefilepath (pull request #111)

Feature/standardisefilepath

* baseprocessing

* generalstructure
This commit is contained in:
Michael McGuinness
2025-04-03 12:13:16 +00:00
parent 81e7223560
commit 1d49313a9f
17 changed files with 466 additions and 253 deletions
+11 -35
View File
@@ -2,13 +2,11 @@ package documentstore
import (
"context"
"fmt"
"log/slog"
"regexp"
docinitrunner "queryorchestration/api/docInitRunner"
doctextprocessrunner "queryorchestration/api/docTextProcessRunner"
"queryorchestration/internal/client"
"queryorchestration/internal/serviceconfig/objectstore"
"queryorchestration/internal/serviceconfig/queue"
)
@@ -31,25 +29,29 @@ func (s *Service) Process(ctx context.Context, params Params) error {
return nil
}
task, clientId := getKeyMetadata(params.Key)
key, err := objectstore.ParseBucketKey(params.Key)
if err != nil {
slog.Error("unable to parse key", "key", params.Key)
return nil
}
queueParams := &queue.SendParams{}
switch task {
case DocInit:
switch key.Location {
case objectstore.Import:
queueParams.QueueURL = s.cfg.GetDocInitURL()
queueParams.Body = docinitrunner.Body{
Bucket: params.Bucket,
Key: params.Key,
Hash: params.Hash,
ClientID: clientId,
ClientID: key.ClientID,
}
case DocTextProcess:
case objectstore.TextTextract:
queueParams.QueueURL = s.cfg.GetDocumentTextProcessURL()
queueParams.Body = doctextprocessrunner.Body{
Bucket: params.Bucket,
Key: params.Key,
Hash: params.Hash,
ClientID: clientId,
ClientID: key.ClientID,
}
default:
slog.Info("unsupported key", "key", params.Key)
@@ -59,32 +61,6 @@ func (s *Service) Process(ctx context.Context, params Params) error {
return s.cfg.SendToQueue(ctx, queueParams)
}
type Task string
const (
DocInit Task = "import"
DocTextProcess Task = "text/textract"
Invalid Task = ""
)
func getKeyMetadata(key string) (Task, string) {
regexStr := fmt.Sprintf(`^(%s)/(import|text/textract)/.+$`, client.CLIENT_ID_REGEX)
re := regexp.MustCompile(regexStr)
match := re.FindStringSubmatch(key)
if len(match) < 3 {
return Invalid, ""
}
task := Task(match[2])
if task == Invalid {
return Invalid, ""
}
clientId := match[1]
return task, clientId
}
func (s *Service) isSupportedEvent(name EventS3) bool {
return name == EventS3ObjectCreatedPut
}