Files
query-orchestration/internal/queryQueue/result.go
T
Michael McGuinness 827d973053 a bit more testing
2024-12-24 12:47:40 +00:00

51 lines
1.1 KiB
Go

package queryQueue
import (
"context"
"fmt"
jsonextractor "gotemplate/internal/jsonExtractor"
"gotemplate/internal/query"
"gotemplate/internal/result"
)
func (q *Queue) setResult(ctx context.Context, qu query.Query, resultValues *[]result.Value) error {
processor, err := q.getProcessor(qu.Type)
if err != nil {
return err
}
value, err := processor.Process(ctx, qu, resultValues)
if err != nil {
return err
}
id, err := result.Store(ctx, q.db, &result.ResultStore{
QueryID: qu.ID,
DocumentID: q.documentId,
Value: value,
CleanVersion: q.cleanVersion,
TextVersion: q.textVersion,
QueryVersion: qu.Version,
})
if err != nil {
return err
}
*q.results = append(*q.results, result.Result{
ID: id,
QueryID: qu.ID,
QueryVersion: qu.Version,
})
return nil
}
func (q *Queue) getProcessor(queryType query.Type) (query.Processor, error) {
switch queryType {
case query.TypeJsonExtractor:
return jsonextractor.New(q.db), nil
default:
return nil, fmt.Errorf("attempting to process invalid query type")
}
}