693457ce2d
Single Text Queue * notrigger
47 lines
939 B
Go
47 lines
939 B
Go
package documentclean
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
doctextrunner "queryorchestration/api/docTextRunner"
|
|
"queryorchestration/internal/serviceconfig/queue"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func (s *Service) Clean(ctx context.Context, documentId uuid.UUID) error {
|
|
isclean, err := s.cfg.GetDBQueries().HasDocumentCleanEntry(ctx, documentId)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to verify if document has been cleaned: %s", err)
|
|
}
|
|
|
|
if !isclean {
|
|
err = s.clean(ctx, documentId)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to clean document: %s", err)
|
|
}
|
|
}
|
|
|
|
err = s.informClean(ctx, documentId)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (s *Service) informClean(ctx context.Context, documentId uuid.UUID) error {
|
|
err := s.cfg.SendToQueue(ctx, &queue.SendParams{
|
|
QueueURL: s.cfg.GetDocumentTextURL(),
|
|
Body: doctextrunner.Body{
|
|
DocumentID: documentId,
|
|
},
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|