Fix assessment job retries and error reporting

This commit is contained in:
biss committed 2026-11-14 19:03:17 +08:00
1 parent 39ddc24699
commit d32387bb67
6 files changed
+40 -10

No files matched your search

@@ -233,6 +233,7 @@ public sealed class BackgroundJobOutboxTests
job.Id);
outbox.State = BackgroundJobOutboxState.Published;
outbox.ProcessingAttempts = 5;
outbox.LastError = "原始处理错误";
db.AddRange(term, plan, job, outbox);
await db.SaveChangesAsync();
envelope = new BackgroundJobEnvelope(
@@ -256,6 +257,7 @@ public sealed class BackgroundJobOutboxTests
Assert.Null(persistedOutbox.ProcessingToken);
Assert.Null(persistedOutbox.LeaseExpiresAt);
Assert.Equal(6, persistedOutbox.ProcessingAttempts);
Assert.Equal("原始处理错误", persistedOutbox.LastError);
var persistedJob = await assertDb.AutomaticScheduleJobs.SingleAsync();
Assert.Equal(AutomaticScheduleJobStatus.Failed, persistedJob.Status);
Assert.Null(persistedJob.ActiveSchedulePlanId);
@@ -3,6 +3,7 @@ using Jiaowu.Api.Controllers;
using Jiaowu.Api.Contracts;
using Jiaowu.Api.Domain.Academic;
using Jiaowu.Api.Domain.Identity;
using Jiaowu.Api.Domain.System;
using Jiaowu.Api.Infrastructure.Assessments;
using Jiaowu.Api.Infrastructure.Auth;
using Jiaowu.Api.Infrastructure.Persistence;
@@ -20,6 +21,25 @@ namespace Jiaowu.Api.Tests;
public sealed class ComprehensiveAssessmentsControllerTests
{
[Fact]
public async Task Manual_recalculation_resets_previous_attempts()
{
await using var fixture = await Fixture.CreateAsync();
fixture.Batch.CalculationStatus = ComprehensiveAssessmentCalculationStatus.Failed;
var outbox = BackgroundJobOutboxMessage.Create(BackgroundJobKind.ComprehensiveAssessmentCalculation, fixture.Batch.Id);
outbox.State = BackgroundJobOutboxState.Completed;
outbox.ProcessingAttempts = 29110;
outbox.LastError = "旧错误";
fixture.Db.BackgroundJobOutboxMessages.Add(outbox);
await fixture.Db.SaveChangesAsync();
var controller = new ComprehensiveAssessmentsController(fixture.Db, fixture.ManagerScope);
Assert.IsType<AcceptedResult>(await controller.QueueCalculation(fixture.Batch.Id, CancellationToken.None));
Assert.Equal(0, outbox.ProcessingAttempts);
Assert.Null(outbox.LastError);
Assert.Equal(BackgroundJobOutboxState.Pending, outbox.State);
}
[Fact]
public async Task Declaration_accepts_attachment_as_evidence_and_obeys_reader_scope()
{