This commit is contained in:
greeneclipse committed 2026-10-20 17:28:06 +02:00
1 parent c83347b9a5
commit fd83a7c523
2 files changed
+27 -3

No files matched your search

+8
View File
@@ -563,6 +563,14 @@ func (p *Pipeline) RetryJob(ctx context.Context, companyID, id uuid.UUID) (Job,
if p.Limiter != nil && !p.Limiter.Allow(companyID) { if p.Limiter != nil && !p.Limiter.Allow(companyID) {
return Job{}, ErrRateLimited return Job{}, ErrRateLimited
} }
// Load the exact output selections saved at job creation, so retry credit
// checks match the original charge (including jobs with a subset of outputs).
var selectedOutputs []string
if err := p.Pool.QueryRow(ctx, `
SELECT processing_types FROM processing_jobs
WHERE id = $1 AND company_id = $2`, id, companyID).Scan(&selectedOutputs); err != nil {
return Job{}, fmt.Errorf("processing: load retry outputs for job %s: %w", id, err)
}
if err := p.assertProcessingGates(ctx, companyID, job.ProcessingType, job.TotalProducts, selectedOutputs...); err != nil { if err := p.assertProcessingGates(ctx, companyID, job.ProcessingType, job.TotalProducts, selectedOutputs...); err != nil {
return Job{}, err return Job{}, err
} }
@@ -86,14 +86,15 @@ func TestRetryJobResetsCompletedJobForFullRerun(t *testing.T) {
firstStep = progress[0].Step firstStep = progress[0].Step
} }
selectedOutputs := []string{"title", "seo_meta"}
var jobID uuid.UUID var jobID uuid.UUID
err = pg.QueryRow(ctx, ` err = pg.QueryRow(ctx, `
INSERT INTO processing_jobs ( INSERT INTO processing_jobs (
company_id, user_id, status, total_products, processed_products, company_id, user_id, status, total_products, processed_products,
processing_type, current_step, step_progress, started_at, completed_at processing_type, processing_types, current_step, step_progress, started_at, completed_at
) VALUES ($1, $2, 'completed', $3, $3, 'full', $4, $5::jsonb, now(), now()) ) VALUES ($1, $2, 'completed', $3, $3, 'full', $4, $5, $6::jsonb, now(), now())
RETURNING id`, RETURNING id`,
companyID, userID, len(rawIDs), firstStep, progressJSON, companyID, userID, len(rawIDs), firstStep, selectedOutputs, progressJSON,
).Scan(&jobID) ).Scan(&jobID)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -131,6 +132,21 @@ func TestRetryJobResetsCompletedJobForFullRerun(t *testing.T) {
t.Fatalf("completed_at should be reset, got %v", *job.CompletedAt) t.Fatalf("completed_at should be reset, got %v", *job.CompletedAt)
} }
// Retrying must preserve the saved processing_types; credit gates and the
// worker both need the original output selections, not legacy defaults.
var persistedOutputs []string
if err := pg.QueryRow(ctx, `SELECT processing_types FROM processing_jobs WHERE id = $1`, jobID).Scan(&persistedOutputs); err != nil {
t.Fatal(err)
}
if len(persistedOutputs) != len(selectedOutputs) {
t.Fatalf("processing_types=%v want %v", persistedOutputs, selectedOutputs)
}
for i := range selectedOutputs {
if persistedOutputs[i] != selectedOutputs[i] {
t.Fatalf("processing_types=%v want %v", persistedOutputs, selectedOutputs)
}
}
var pendingCount, processedCount int var pendingCount, processedCount int
err = pg.QueryRow(ctx, ` err = pg.QueryRow(ctx, `
SELECT SELECT