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 querysyncrunner
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
|
||||
querysync "queryorchestration/internal/query/sync"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
||||
)
|
||||
|
||||
const Name = "querySyncRunner"
|
||||
@@ -32,24 +29,11 @@ func New(validator *validator.Validate, svc *Services) Runner {
|
||||
}
|
||||
|
||||
type Body struct {
|
||||
ID uuid.UUID `json:"id" validate:"required,uuid"`
|
||||
DocumentID uuid.UUID `json:"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.QuerySync.Sync(ctx, body.ID)
|
||||
func (s *Runner) Process(ctx context.Context, body Body) bool {
|
||||
err := s.svc.QuerySync.Sync(ctx, body.DocumentID)
|
||||
if err != nil {
|
||||
slog.Error("unable to process", "error", err)
|
||||
return false
|
||||
|
||||
@@ -2,7 +2,6 @@ package querysyncrunner_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
@@ -15,7 +14,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"
|
||||
@@ -25,7 +23,7 @@ import (
|
||||
)
|
||||
|
||||
type QuerySyncConfig struct {
|
||||
runner.BaseConfig
|
||||
runner.BaseConfig[querysyncrunner.Body]
|
||||
queryc.QueryConfig
|
||||
}
|
||||
|
||||
@@ -53,13 +51,7 @@ func TestQueryRunner(t *testing.T) {
|
||||
|
||||
t.Run("valid", func(t *testing.T) {
|
||||
doc := querysyncrunner.Body{
|
||||
ID: uuid.New(),
|
||||
}
|
||||
bodyBytes, err := json.Marshal(doc)
|
||||
require.NoError(t, err)
|
||||
body := string(bodyBytes)
|
||||
msg := &types.Message{
|
||||
Body: &body,
|
||||
DocumentID: uuid.New(),
|
||||
}
|
||||
|
||||
reqId := uuid.New()
|
||||
@@ -67,12 +59,12 @@ func TestQueryRunner(t *testing.T) {
|
||||
reqId,
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: IsDocumentTextExtracted :one").WithArgs(doc.ID).
|
||||
pool.ExpectQuery("name: IsDocumentTextExtracted :one").WithArgs(doc.DocumentID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"isextracted"}).
|
||||
AddRow(true),
|
||||
)
|
||||
pool.ExpectQuery("name: ListUnsyncedNoDepsQueriesByDocId :many").WithArgs(&doc.ID).
|
||||
pool.ExpectQuery("name: ListUnsyncedNoDepsQueriesByDocId :many").WithArgs(&doc.DocumentID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(&reqId),
|
||||
@@ -82,22 +74,12 @@ func TestQueryRunner(t *testing.T) {
|
||||
SendMessage(
|
||||
mock.Anything,
|
||||
mock.MatchedBy(func(in *sqs.SendMessageInput) bool {
|
||||
return *in.QueueUrl == cfg.QueryURL && *in.MessageBody == fmt.Sprintf("{\"document_id\":\"%s\",\"query_id\":\"%s\"}", doc.ID.String(), qs[0].String())
|
||||
return *in.QueueUrl == cfg.QueryURL && *in.MessageBody == fmt.Sprintf("{\"document_id\":\"%s\",\"query_id\":\"%s\"}", doc.DocumentID.String(), qs[0].String())
|
||||
}),
|
||||
mock.Anything,
|
||||
).
|
||||
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