Merged in fature/jobs (pull request #34)

Job Collector

* createstructure

* mostupdatevalidation

* repocollectorupdate

* updateoutline

* updatevalidation

* scriptupdate

* cleanupdockerignore

* update

* collectorupdateapi
This commit is contained in:
Michael McGuinness
2025-01-23 14:56:20 +00:00
parent 36967fc946
commit 5b7160fe44
88 changed files with 2181 additions and 297 deletions
+5 -2
View File
@@ -7,6 +7,7 @@ import (
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/job/collector"
"queryorchestration/internal/query"
"queryorchestration/internal/query/document"
"testing"
@@ -32,7 +33,9 @@ func TestQueryRunner(t *testing.T) {
}
svc := document.New(db, &document.Services{
Collector: collector.New(db),
Collector: collector.New(db, &collector.Services{
Query: query.New(db),
}),
})
runner := controllers.NewQueryRunner(svc, validator.New())
@@ -61,7 +64,7 @@ func TestQueryRunner(t *testing.T) {
pool.ExpectQuery("name: GetCollectorByJobID :one").WithArgs(database.MustToDBUUID(doc.JobID)).
WillReturnRows(
pgxmock.NewRows([]string{"id", "jobId", "minCleanVersion", "minTextVersion", "activeVersion", "latestVersion", "fields"}).
AddRow(collectorID, database.MustToDBUUID(doc.JobID), minCleanVersion, minTextVersion, int32(1), int32(2), []byte("")),
AddRow(collectorID, database.MustToDBUUID(doc.JobID), &minCleanVersion, &minTextVersion, int32(1), int32(2), []byte("")),
)
pool.ExpectQuery("name: ListResultsByDocumentID :many").WithArgs(database.MustToDBUUID(doc.ID), minCleanVersion, minTextVersion).
WillReturnRows(
+36 -1
View File
@@ -3,6 +3,7 @@ package queryservice
import (
"fmt"
"net/http"
"queryorchestration/internal/job/collector"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
@@ -40,5 +41,39 @@ func (s *Controllers) GetJobCollectorByJobId(ctx echo.Context, jobId string) err
}
func (s *Controllers) UpdateJobCollectorByJobId(ctx echo.Context, jobId string) error {
return ctx.JSON(http.StatusOK, map[string]string{"status": "export triggered"})
req := JobCollectorUpdate{}
if err := ctx.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
}
uid, err := uuid.Parse(jobId)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid ID")
}
var fields *map[string]uuid.UUID
if req.Fields != nil {
fields := &map[string]uuid.UUID{}
for _, field := range *req.Fields {
queryId, err := uuid.Parse(field.QueryId)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid ID")
}
(*fields)[field.Name] = queryId
}
}
err = s.svc.JobCollector.UpdateByJobId(ctx.Request().Context(), &collector.UpdateParams{
JobID: uid,
ActiveVersion: req.ActiveVersion,
MinCleanVersion: req.MinimumCleanerVersion,
MinTextVersion: req.MinimumTextVersion,
Fields: fields,
})
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to update query: %s", err))
}
return ctx.NoContent(http.StatusOK)
}
+54 -7
View File
@@ -7,31 +7,76 @@ import (
queryservice "queryorchestration/api/queryService"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
documentclean "queryorchestration/internal/document_clean"
"queryorchestration/internal/job/collector"
"queryorchestration/internal/query"
textextraction "queryorchestration/internal/text_extraction"
"strings"
"testing"
"github.com/go-playground/validator/v10"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/labstack/echo/v4"
"github.com/pashagolub/pgxmock/v3"
"github.com/stretchr/testify/assert"
)
func TestUpdateJobCollector(t *testing.T) {
pool, err := pgxmock.NewPool()
if err != nil {
t.Fatalf("failed to open pgxmock database: %v", err)
}
queries := repository.New(pool)
db := &database.Connection{
Queries: queries,
Pool: pool,
}
av := int32(2)
body := queryservice.JobCollectorUpdate{
ActiveVersion: &av,
}
bodyBytes, err := json.Marshal(body)
assert.Nil(t, err)
e := echo.New()
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(""))
req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(string(bodyBytes)))
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
rec := httptest.NewRecorder()
ctx := e.NewContext(req, rec)
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{})
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
JobCollector: collector.New(db, &collector.Services{
Query: query.New(db),
DocumentClean: documentclean.New(),
TextExtraction: textextraction.New(),
}),
})
id := uuid.New()
current := collector.Collector{
ID: uuid.New(),
JobID: uuid.New(),
ActiveVersion: 1,
LatestVersion: 4,
}
err := cons.UpdateJobCollectorByJobId(ctx, id.String())
ctx.Set("id", current.JobID)
pool.ExpectQuery("name: GetCollectorByJobID :one").WithArgs(database.MustToDBUUID(current.JobID)).
WillReturnRows(
pgxmock.NewRows([]string{"id", "jobId", "minCleanVersion", "minTextVersion", "activeVersion", "latestVersion", "fields"}).
AddRow(database.MustToDBUUID(current.ID), database.MustToDBUUID(current.JobID), &current.MinCleanVersion, &current.MinTextVersion, current.ActiveVersion, current.LatestVersion, []byte("")),
)
pool.ExpectBeginTx(pgx.TxOptions{})
pool.ExpectExec("name: UpdateCollector :exec").WithArgs(int32(5), int32(2), database.MustToDBUUID(current.ID)).
WillReturnResult(pgxmock.NewResult("", 1))
pool.ExpectCommit()
err = cons.UpdateJobCollectorByJobId(ctx, current.JobID.String())
assert.Nil(t, err)
assert.Equal(t, http.StatusOK, rec.Code)
assert.NotEmpty(t, rec.Body.String())
assert.Empty(t, rec.Body.String())
}
func TestGetJobCollectorByJobId(t *testing.T) {
@@ -50,7 +95,9 @@ func TestGetJobCollectorByJobId(t *testing.T) {
rec := httptest.NewRecorder()
ctx := e.NewContext(req, rec)
svc := collector.New(db)
svc := collector.New(db, &collector.Services{
Query: query.New(db),
})
cons := queryservice.NewControllers(validator.New(), &queryservice.Services{
JobCollector: svc,
})
@@ -65,7 +112,7 @@ func TestGetJobCollectorByJobId(t *testing.T) {
pool.ExpectQuery("name: GetCollectorByJobID :one").WithArgs(database.MustToDBUUID(coll.JobID)).
WillReturnRows(
pgxmock.NewRows([]string{"id", "jobId", "minCleanVersion", "minTextVersion", "activeVersion", "latestVersion", "fields"}).
AddRow(database.MustToDBUUID(coll.ID), database.MustToDBUUID(coll.JobID), coll.MinCleanVersion, coll.MinTextVersion, int32(1), int32(2), []byte("")),
AddRow(database.MustToDBUUID(coll.ID), database.MustToDBUUID(coll.JobID), &coll.MinCleanVersion, &coll.MinTextVersion, int32(1), int32(2), []byte("")),
)
err = cons.GetJobCollectorByJobId(ctx, coll.JobID.String())
+5 -2
View File
@@ -167,7 +167,10 @@ func TestUpdateQuery(t *testing.T) {
Query: query.New(db),
})
body := queryservice.QueryUpdate{}
av := int32(2)
body := queryservice.QueryUpdate{
ActiveVersion: &av,
}
bodyBytes, err := json.Marshal(body)
assert.Nil(t, err)
@@ -187,7 +190,7 @@ func TestUpdateQuery(t *testing.T) {
)
pool.ExpectBeginTx(pgx.TxOptions{})
pool.ExpectExec("name: UpdateQuery :exec").WithArgs(int32(1), int32(2), database.MustToDBUUID(id)).
pool.ExpectExec("name: UpdateQuery :exec").WithArgs(av, int32(3), database.MustToDBUUID(id)).
WillReturnResult(pgxmock.NewResult("", 1))
pool.ExpectCommit()