Merged in feature/batch-status (pull request #215)

Implement and test the batch status feature

* working
This commit is contained in:
Jay Brown
2026-03-12 18:53:42 +00:00
parent 8a4029058b
commit aafe7d5b5f
39 changed files with 4252 additions and 516 deletions
+29 -1
View File
@@ -4,6 +4,8 @@ import (
"context"
"log/slog"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/document/batch/outcome"
documentsync "queryorchestration/internal/document/sync"
"github.com/google/uuid"
@@ -11,30 +13,56 @@ import (
const Name = "docSyncRunner"
// Services holds the dependencies for the docSyncRunner.
//
// Fields:
// - Document: service for syncing documents
// - Outcome: reporter for writing batch pipeline outcomes
type Services struct {
Document *documentsync.Service
Outcome *outcome.Reporter
}
// Runner processes document sync messages from the SQS queue.
type Runner struct {
svc *Services
}
// New creates a new docSyncRunner.
//
// Parameters:
// - svc: the runner's service dependencies
//
// Returns:
// - Runner: the runner instance
func New(svc *Services) Runner {
return Runner{
svc: svc,
}
}
// Body is the SQS message body for docSyncRunner.
type Body struct {
DocumentID uuid.UUID `json:"id" validate:"required,uuid"`
}
// Process handles a single document sync message. Returns true to acknowledge
// the message (success), or false to requeue (infrastructure error).
func (s Runner) Process(ctx context.Context, body Body) bool {
err := s.svc.Document.Sync(ctx, body.DocumentID)
result, err := s.svc.Document.Sync(ctx, body.DocumentID)
if err != nil {
slog.Error("unable to process", "error", err)
return false
}
outcomeName := repository.BatchOutcomeStatusSyncComplete
if result.Skipped {
outcomeName = repository.BatchOutcomeStatusSyncSkipped
}
if updateErr := s.svc.Outcome.Update(ctx, body.DocumentID, outcomeName, nil); updateErr != nil {
slog.Error("failed to update batch outcome",
"document_id", body.DocumentID, "outcome", outcomeName, "error", updateErr)
}
return true
}