can grab all queries required to fulfill a collector
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user