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 docsyncrunner
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
|
||||
documentsync "queryorchestration/internal/document/sync"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
||||
)
|
||||
|
||||
const Name = "docSyncRunner"
|
||||
@@ -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.Document.Sync(ctx, body.ID)
|
||||
func (s Runner) Process(ctx context.Context, body Body) bool {
|
||||
err := s.svc.Document.Sync(ctx, body.DocumentID)
|
||||
if err != nil {
|
||||
slog.Error("unable to process", "error", err)
|
||||
return false
|
||||
|
||||
@@ -2,7 +2,6 @@ package docsyncrunner_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
@@ -11,12 +10,11 @@ import (
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
documentsync "queryorchestration/internal/document/sync"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/server/runner"
|
||||
"queryorchestration/internal/serviceconfig/queue/documentclean"
|
||||
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"
|
||||
@@ -26,7 +24,7 @@ import (
|
||||
)
|
||||
|
||||
type DocSyncConfig struct {
|
||||
serviceconfig.BaseConfig
|
||||
runner.BaseConfig[docsyncrunner.Body]
|
||||
documentclean.DocCleanConfig
|
||||
}
|
||||
|
||||
@@ -52,20 +50,14 @@ func TestDocInitRunner(t *testing.T) {
|
||||
|
||||
t.Run("valid", func(t *testing.T) {
|
||||
j := client.Client{
|
||||
ID: uuid.New(),
|
||||
ID: "hello",
|
||||
}
|
||||
docinfo := document.DocumentSummary{
|
||||
ID: uuid.New(),
|
||||
ClientID: j.ID,
|
||||
}
|
||||
doc := docsyncrunner.Body{
|
||||
ID: docinfo.ID,
|
||||
}
|
||||
bodyBytes, err := json.Marshal(doc)
|
||||
require.NoError(t, err)
|
||||
body := string(bodyBytes)
|
||||
msg := &types.Message{
|
||||
Body: &body,
|
||||
DocumentID: docinfo.ID,
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(docinfo.ID).
|
||||
@@ -75,30 +67,20 @@ func TestDocInitRunner(t *testing.T) {
|
||||
)
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(j.ID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "externalId", "name", "canSync"}).
|
||||
AddRow(j.ID, "client_id", "client_name", true),
|
||||
pgxmock.NewRows([]string{"id", "name", "canSync"}).
|
||||
AddRow(j.ID, "client_name", true),
|
||||
)
|
||||
|
||||
mockSQS.EXPECT().
|
||||
SendMessage(
|
||||
mock.Anything,
|
||||
mock.MatchedBy(func(in *sqs.SendMessageInput) bool {
|
||||
return *in.QueueUrl == cfg.DocumentCleanURL && *in.MessageBody == fmt.Sprintf("{\"id\":\"%s\"}", doc.ID)
|
||||
return *in.QueueUrl == cfg.DocumentCleanURL && *in.MessageBody == fmt.Sprintf("{\"id\":\"%s\"}", doc.DocumentID)
|
||||
}),
|
||||
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