Files
query-orchestration/internal/document/sync/sync.go
T
Jay Brown aafe7d5b5f Merged in feature/batch-status (pull request #215)
Implement and test the batch status feature

* working
2026-03-12 18:53:42 +00:00

63 lines
1.5 KiB
Go

package documentsync
import (
"context"
"log/slog"
doccleanrunner "queryorchestration/api/docCleanRunner"
"queryorchestration/internal/serviceconfig/queue"
"github.com/google/uuid"
)
// SyncResult contains the result of the sync check.
//
// Fields:
// - Synced: true if the document was forwarded to the clean queue
// - Skipped: true if the client's can_sync flag is false
type SyncResult struct {
Synced bool
Skipped bool
}
// Sync checks if a document is eligible for syncing based on the client's
// can_sync configuration, and forwards eligible documents to the clean queue.
//
// Parameters:
// - ctx: request context
// - id: the document UUID to sync
//
// Returns:
// - *SyncResult: result indicating whether sync was performed or skipped
// - error: if any infrastructure operation (DB, queue) fails
func (s *Service) Sync(ctx context.Context, id uuid.UUID) (*SyncResult, error) {
doc, err := s.svc.Document.GetSummary(ctx, id)
if err != nil {
return nil, err
}
j, err := s.svc.Client.Get(ctx, doc.ClientID)
if err != nil {
return nil, err
}
if !j.CanSync {
slog.Debug("not syncing document", "id", id.String())
return &SyncResult{Skipped: true}, nil
}
slog.Debug("syncing document", "id", id.String())
err = s.cfg.SendToQueue(ctx, &queue.SendParams{
QueueURL: s.cfg.GetDocumentCleanURL(),
Body: doccleanrunner.Body{
DocumentID: id,
},
})
if err != nil {
return nil, err
}
return &SyncResult{Synced: true}, nil
}