0815cb35fb
Basic Lint Checks * basic
50 lines
928 B
Go
50 lines
928 B
Go
package documenttext
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
|
|
querysyncrunner "queryorchestration/api/querySyncRunner"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/serviceconfig/queue"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func (s *Service) Extract(ctx context.Context, id uuid.UUID) error {
|
|
slog.Debug("extracting document text", "id", id.String())
|
|
|
|
isextracted, err := s.cfg.GetDBQueries().IsDocumentTextExtracted(ctx, database.MustToDBUUID(id))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if !isextracted {
|
|
err = s.extract(ctx, id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
err = s.informExtraction(ctx, id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (s *Service) informExtraction(ctx context.Context, id uuid.UUID) error {
|
|
err := s.cfg.SendToQueue(ctx, &queue.SendParams{
|
|
QueueURL: s.cfg.GetQuerySyncURL(),
|
|
Body: querysyncrunner.Body{
|
|
ID: id,
|
|
},
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|