f11f4def43
Clean Set Up * fail * starteddb * constraint * cleantest * fixqueries * fixtests * storemimetype * buffer * tests * setup * passingtests * pdfHElloWorld * rm * test * notodos * tests * clean * testpdf
46 lines
829 B
Go
46 lines
829 B
Go
package documentclean
|
|
|
|
import (
|
|
"context"
|
|
doctextrunner "queryorchestration/api/docTextRunner"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/serviceconfig/queue"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func (s *Service) Clean(ctx context.Context, id uuid.UUID) error {
|
|
isclean, err := s.cfg.GetDBQueries().HasDocumentCleanEntry(ctx, database.MustToDBUUID(id))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if !isclean {
|
|
err = s.clean(ctx, id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
err = s.informClean(ctx, id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (s *Service) informClean(ctx context.Context, id uuid.UUID) error {
|
|
err := s.cfg.SendToQueue(ctx, &queue.SendParams{
|
|
QueueURL: s.cfg.GetDocumentTextURL(),
|
|
Body: doctextrunner.Body{
|
|
ID: id,
|
|
},
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|