Merged in feature/textextraction (pull request #110)
Text Extraction * bases * go * splitting * structure * movetoasync * movetoasync * settinguptrigger * reorder * storevent * standardisepollingvalidation * unittests * fixlint * fixlint * awscfg * generatesample * followthrough * tests * clena * store * externalidcleanup * clientid * local * baseunittests * putobjecttests * tests
This commit is contained in:
@@ -2,15 +2,12 @@ package queryrunner
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
|
||||
resultset "queryorchestration/internal/query/result/set"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
||||
)
|
||||
|
||||
const Name = "queryRunner"
|
||||
@@ -36,21 +33,8 @@ type Body struct {
|
||||
QueryID uuid.UUID `json:"query_id" validate:"required,uuid"`
|
||||
}
|
||||
|
||||
func (s *Runner) Process(ctx context.Context, req *types.Message) bool {
|
||||
var body Body
|
||||
err := json.Unmarshal([]byte(*req.Body), &body)
|
||||
if err != nil {
|
||||
slog.Error("parsing body", "messageId", *req.MessageId, "body", *req.Body)
|
||||
return true
|
||||
}
|
||||
|
||||
err = s.validator.Struct(body)
|
||||
if err != nil {
|
||||
slog.Error("invalid body", "messageId", *req.MessageId, "error", err)
|
||||
return true
|
||||
}
|
||||
|
||||
err = s.svc.ResultSet.Set(ctx, &resultset.Set{
|
||||
func (s *Runner) Process(ctx context.Context, body Body) bool {
|
||||
err := s.svc.ResultSet.Set(ctx, &resultset.Set{
|
||||
DocumentID: body.DocumentID,
|
||||
QueryID: body.QueryID,
|
||||
})
|
||||
|
||||
@@ -2,7 +2,6 @@ package queryrunner_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
@@ -18,7 +17,6 @@ import (
|
||||
queuemock "queryorchestration/mocks/queue"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/google/uuid"
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
@@ -28,7 +26,7 @@ import (
|
||||
)
|
||||
|
||||
type QueryConfig struct {
|
||||
runner.BaseConfig
|
||||
runner.BaseConfig[queryrunner.Body]
|
||||
queryc.QueryConfig
|
||||
}
|
||||
|
||||
@@ -58,16 +56,10 @@ func TestQueryRunner(t *testing.T) {
|
||||
assert.NotNil(t, runner)
|
||||
|
||||
t.Run("valid", func(t *testing.T) {
|
||||
doc := resultset.Set{
|
||||
doc := queryrunner.Body{
|
||||
DocumentID: uuid.New(),
|
||||
QueryID: uuid.New(),
|
||||
}
|
||||
bodyBytes, err := json.Marshal(doc)
|
||||
require.NoError(t, err)
|
||||
body := string(bodyBytes)
|
||||
msg := &types.Message{
|
||||
Body: &body,
|
||||
}
|
||||
|
||||
qcfg := "{\"path\":\"examplekey\"}"
|
||||
reqQuery := uuid.New()
|
||||
@@ -81,12 +73,11 @@ func TestQueryRunner(t *testing.T) {
|
||||
DocumentID: doc.DocumentID,
|
||||
}
|
||||
|
||||
cleanEntryId := uuid.New()
|
||||
textEntryId := uuid.New()
|
||||
pool.ExpectQuery("name: GetTextEntryByDocId :one").WithArgs(params.DocumentID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "hash", "cleanEntryId"}).
|
||||
AddRow(textEntryId, params.DocumentID, "buket", "/i/am/here", int32(1), "example", cleanEntryId),
|
||||
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "hash", "cleanId", "triggerId", "textractJobId", "triggerVersion", "extractionVersion"}).
|
||||
AddRow(textEntryId, params.DocumentID, "buket", "/i/am/here", "example", uuid.New(), uuid.New(), "jobId", int64(123), int64(543)),
|
||||
)
|
||||
pool.ExpectQuery("name: GetQuery :one").WithArgs(query.ID).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
|
||||
@@ -138,16 +129,6 @@ func TestQueryRunner(t *testing.T) {
|
||||
).
|
||||
Return(&sqs.SendMessageOutput{}, nil)
|
||||
|
||||
assert.True(t, runner.Process(ctx, msg))
|
||||
})
|
||||
t.Run("invalid body", func(t *testing.T) {
|
||||
body := "definitely invalid"
|
||||
msgId := "id"
|
||||
msg := &types.Message{
|
||||
Body: &body,
|
||||
MessageId: &msgId,
|
||||
}
|
||||
|
||||
assert.True(t, runner.Process(ctx, msg))
|
||||
assert.True(t, runner.Process(ctx, doc))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user