can grab all queries required to fulfill a collector

This commit is contained in:
Michael McGuinness
2024-12-19 18:49:22 +00:00
parent 5221ca7fc7
commit 66fcc78887
141 changed files with 1917 additions and 1454 deletions
+45 -7
View File
@@ -2,7 +2,11 @@ package document
import (
"context"
"gotemplate/internal/database"
"gotemplate/internal/database/repository"
"log"
"github.com/google/uuid"
)
type Service struct {
@@ -10,9 +14,9 @@ type Service struct {
}
type Document struct {
ID string `json:"id"`
JobID string `json:"jobId"`
Name string `json:"name"`
ID uuid.UUID `json:"id"`
JobID uuid.UUID `json:"jobId"`
Name string `json:"name"`
}
func New(ctx context.Context, db *repository.Queries) *Service {
@@ -22,9 +26,43 @@ func New(ctx context.Context, db *repository.Queries) *Service {
}
func (s *Service) Sync(ctx context.Context, doc Document) error {
// Check if collector exists for doc and is synced
// Check if job set up
// If not find all outputs and see if any are out of sync/missing
// create dependency tree - if sync triggered, sync all dependent outputs by using queue
jobID, err := database.ToDBUUID(doc.JobID)
if err != nil {
return err
}
queries, err := s.db.GetQueriesFromJobID(ctx, jobID)
if err != nil {
return err
}
docID, err := database.ToDBUUID(doc.ID)
if err != nil {
return err
}
results, err := s.db.ListResultsByDocumentID(ctx, docID)
if err != nil {
return err
}
for _, query := range queries {
isSynced := false
for _, result := range results {
if result.Queryid != query.ID {
continue
}
isSynced = result.Cleanversion >= query.Mincleanversion && result.Textversion >= query.Mintextversion && result.Queryversion != query.Queryversion
break
}
if isSynced {
continue
}
log.Print("TODO sync me pls")
// Check if exists and synced
// IF NOT synced then add to queue, as well as all dependents recursively
}
// TODO what to do with results that are not used
return nil
}