2025-02-12 19:00:25 +00:00
|
|
|
package documentsync
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"log/slog"
|
2025-03-05 12:05:46 +00:00
|
|
|
|
2025-02-12 19:00:25 +00:00
|
|
|
doccleanrunner "queryorchestration/api/docCleanRunner"
|
|
|
|
|
"queryorchestration/internal/serviceconfig/queue"
|
|
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (s *Service) Sync(ctx context.Context, id uuid.UUID) error {
|
|
|
|
|
doc, err := s.svc.Document.Get(ctx, id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
j, err := s.svc.Job.Get(ctx, doc.JobID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !j.CanSync {
|
|
|
|
|
slog.Debug("not syncing document", "id", id.String())
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
slog.Debug("syncing document", "id", id.String())
|
|
|
|
|
|
|
|
|
|
err = s.cfg.SendToQueue(ctx, &queue.SendParams{
|
|
|
|
|
QueueURL: s.cfg.GetDocumentCleanURL(),
|
|
|
|
|
Body: doccleanrunner.Body{
|
|
|
|
|
ID: id,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|