aafe7d5b5f
Implement and test the batch status feature * working
63 lines
1.5 KiB
Go
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
|
|
}
|