synctest
This commit is contained in:
@@ -2,8 +2,8 @@ package queryQueue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/query"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/query"
|
||||
)
|
||||
|
||||
func (q *Queue) getUnsyncedQueries() {
|
||||
@@ -75,7 +75,7 @@ func (q *Queue) Add(qu *query.Query) {
|
||||
}
|
||||
|
||||
if requiredIndex != -1 {
|
||||
*q.unsyncedQueue = append((*q.unsyncedQueue)[:requiredIndex], append([]query.Query{*qu}, (*q.unsyncedQueue)[requiredIndex:]...)...)
|
||||
*q.unsyncedQueue = append((*q.unsyncedQueue)[:requiredIndex+1], append([]query.Query{*qu}, (*q.unsyncedQueue)[requiredIndex+1:]...)...)
|
||||
} else {
|
||||
*q.unsyncedQueue = append([]query.Query{*qu}, *q.unsyncedQueue...)
|
||||
}
|
||||
|
||||
@@ -2,9 +2,13 @@ package queryQueue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/query"
|
||||
"gotemplate/internal/result"
|
||||
"fmt"
|
||||
contextfull "queryorchestration/internal/contextFull"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
jsonextractor "queryorchestration/internal/jsonExtractor"
|
||||
"queryorchestration/internal/query"
|
||||
"queryorchestration/internal/result"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
@@ -59,9 +63,13 @@ func (q *Queue) executeQuery(ctx context.Context, qu query.Query) error {
|
||||
}
|
||||
|
||||
cleanValues := make([]result.Value, len(values))
|
||||
for _, r := range values {
|
||||
cleanValue := result.ParseValue(&r)
|
||||
cleanValues = append(cleanValues, *cleanValue)
|
||||
for index, r := range values {
|
||||
cleanValue, err := q.getResultValue(&r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cleanValues[index] = cleanValue
|
||||
}
|
||||
|
||||
err = q.setResult(ctx, qu, &cleanValues)
|
||||
@@ -71,3 +79,21 @@ func (q *Queue) executeQuery(ctx context.Context, qu query.Query) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *Queue) getResultValue(res *repository.ListResultValuesByIDRow) (result.Value, error) {
|
||||
var queryType query.Type
|
||||
for _, qu := range *q.collectorQueries {
|
||||
if qu.ID == database.MustToUUID(res.Queryid) {
|
||||
queryType = qu.Type
|
||||
}
|
||||
}
|
||||
|
||||
switch queryType {
|
||||
case query.TypeJsonExtractor:
|
||||
return jsonextractor.NewResult(res.Value), nil
|
||||
case query.TypeContextFull:
|
||||
return contextfull.NewResult(res.Value), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("attempting to process invalid query type")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,10 @@ package queryQueue
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
jsonextractor "gotemplate/internal/jsonExtractor"
|
||||
"gotemplate/internal/query"
|
||||
"gotemplate/internal/result"
|
||||
contextfull "queryorchestration/internal/contextFull"
|
||||
jsonextractor "queryorchestration/internal/jsonExtractor"
|
||||
"queryorchestration/internal/query"
|
||||
"queryorchestration/internal/result"
|
||||
)
|
||||
|
||||
func (q *Queue) setResult(ctx context.Context, qu query.Query, resultValues *[]result.Value) error {
|
||||
@@ -44,6 +45,8 @@ func (q *Queue) getProcessor(queryType query.Type) (query.Processor, error) {
|
||||
switch queryType {
|
||||
case query.TypeJsonExtractor:
|
||||
return jsonextractor.New(q.db), nil
|
||||
case query.TypeContextFull:
|
||||
return contextfull.New(), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("attempting to process invalid query type")
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ package queryQueue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/collector"
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/query"
|
||||
"gotemplate/internal/result"
|
||||
"queryorchestration/internal/collector"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/query"
|
||||
"queryorchestration/internal/result"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user