fix(analysis): one failed sequence is the job's error as logged; workers never fault while stopping
"1 sequenze su 3" read wrong in Italian: a single failure now reports its own line (title and reason); the count is kept for two or more. A worker whose job could not be finished while the engine stops logs it instead of faulting, so disposing the engine never throws. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
4 files changed
+10
-6
No files matched your search
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
<resheader name="version"><value>2.0</value></resheader>
|
<resheader name="version"><value>2.0</value></resheader>
|
||||||
<resheader name="reader"><value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader>
|
<resheader name="reader"><value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader>
|
||||||
<resheader name="writer"><value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader>
|
<resheader name="writer"><value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader>
|
||||||
<data name="Errors.Analysis.Failed" xml:space="preserve"><value>{0} of {1} sequences could not be analysed; see the job log.</value><comment>long; {0} failed count; {1} total count</comment></data>
|
<data name="Errors.Analysis.Failed" xml:space="preserve"><value>{0} of {1} sequences could not be analysed; see the job log.</value><comment>long; {0} failed count (2 or more); {1} total count</comment></data>
|
||||||
<data name="Errors.Archive.Open" xml:space="preserve"><value>The archive could not be opened.</value><comment>long</comment></data>
|
<data name="Errors.Archive.Open" xml:space="preserve"><value>The archive could not be opened.</value><comment>long</comment></data>
|
||||||
<data name="Errors.Number.Range" xml:space="preserve"><value>Enter a whole number from {0} to {1}.</value></data>
|
<data name="Errors.Number.Range" xml:space="preserve"><value>Enter a whole number from {0} to {1}.</value></data>
|
||||||
<data name="Errors.Path.Empty" xml:space="preserve"><value>Enter a folder.</value></data>
|
<data name="Errors.Path.Empty" xml:space="preserve"><value>Enter a folder.</value></data>
|
||||||
|
|||||||
@@ -220,9 +220,10 @@ public sealed class JobEngine : IAsyncDisposable
|
|||||||
{
|
{
|
||||||
await RunAsync(job, shutdown).ConfigureAwait(false);
|
await RunAsync(job, shutdown).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception ex) when (!shutdown.IsCancellationRequested)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// The job's final state could not be stored; it stays running and is requeued at the next start.
|
// The job's final state could not be stored (also while stopping): it stays running and is requeued at the
|
||||||
|
// next start. The worker never faults, so disposing the engine never throws.
|
||||||
Log.Error("jobs", $"{job.Kind} job {job.Id} could not be finished", ex);
|
Log.Error("jobs", $"{job.Kind} job {job.Id} could not be finished", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ internal sealed class AnalyseJobHandler(TitanoDatabase db, SequenceAnalyser anal
|
|||||||
var total = units.Sum();
|
var total = units.Sum();
|
||||||
var done = Enumerable.Range(0, next).Where(i => !retry.Contains(i)).Sum(i => units[i]);
|
var done = Enumerable.Range(0, next).Where(i => !retry.Contains(i)).Sum(i => units[i]);
|
||||||
var failed = new List<int>();
|
var failed = new List<int>();
|
||||||
|
string? failure = null;
|
||||||
int[] order = [.. retry, .. Enumerable.Range(next, targets.Count - next)];
|
int[] order = [.. retry, .. Enumerable.Range(next, targets.Count - next)];
|
||||||
for (var k = 0; k < order.Length; k++)
|
for (var k = 0; k < order.Length; k++)
|
||||||
{
|
{
|
||||||
@@ -49,7 +50,8 @@ internal sealed class AnalyseJobHandler(TitanoDatabase db, SequenceAnalyser anal
|
|||||||
{
|
{
|
||||||
await chain.FlushAsync().ConfigureAwait(false);
|
await chain.FlushAsync().ConfigureAwait(false);
|
||||||
Core.Diagnostics.Log.Warning("processing", $"Analysis of sequence {targets[i]} failed", ex);
|
Core.Diagnostics.Log.Warning("processing", $"Analysis of sequence {targets[i]} failed", ex);
|
||||||
context.Log(Loc.L("Advisor.Log.Failed", await TitleAsync(targets[i], context.Cancellation).ConfigureAwait(false), ex.Message));
|
failure = Loc.L("Advisor.Log.Failed", await TitleAsync(targets[i], context.Cancellation).ConfigureAwait(false), ex.Message);
|
||||||
|
context.Log(failure);
|
||||||
failed.Add(i);
|
failed.Add(i);
|
||||||
}
|
}
|
||||||
done += units[i];
|
done += units[i];
|
||||||
@@ -57,7 +59,8 @@ internal sealed class AnalyseJobHandler(TitanoDatabase db, SequenceAnalyser anal
|
|||||||
// Failed targets of an earlier attempt not retried yet stay listed.
|
// Failed targets of an earlier attempt not retried yet stay listed.
|
||||||
await context.CheckpointAsync(Format(next, [.. failed, .. retry.Skip(k + 1)]), done, total).ConfigureAwait(false);
|
await context.CheckpointAsync(Format(next, [.. failed, .. retry.Skip(k + 1)]), done, total).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
if (failed.Count > 0) throw new InvalidOperationException(Loc.L("Errors.Analysis.Failed", failed.Count, targets.Count));
|
// One failure is the job's error as it was logged; several are counted (the log names each).
|
||||||
|
if (failed.Count > 0) throw new InvalidOperationException(failed.Count == 1 ? failure : Loc.L("Errors.Analysis.Failed", failed.Count, targets.Count));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<string> TitleAsync(Guid sequenceId, CancellationToken cancellationToken) =>
|
private async Task<string> TitleAsync(Guid sequenceId, CancellationToken cancellationToken) =>
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ public sealed class AnalysisJobTests(TestContext context)
|
|||||||
|
|
||||||
var job = await fx.EnqueueAsync(ProcessingJobs.LightAnalysis([a.Id, b.Id, c.Id]));
|
var job = await fx.EnqueueAsync(ProcessingJobs.LightAnalysis([a.Id, b.Id, c.Id]));
|
||||||
var failed = await fx.WaitForAsync(job.Id, JobState.Failed);
|
var failed = await fx.WaitForAsync(job.Id, JobState.Failed);
|
||||||
Assert.Equal(Loc.L("Errors.Analysis.Failed", 1, 3), failed.Error);
|
Assert.True(failed.Error!.StartsWith(Loc.L("Advisor.Log.Failed", b.DisplayTitle, string.Empty), StringComparison.Ordinal), failed.Error);
|
||||||
Assert.Equal("3;1", failed.Checkpoint);
|
Assert.Equal("3;1", failed.Checkpoint);
|
||||||
Assert.SequenceEqual([true, false, true], await AnalysedAsync(fx, a, b, c));
|
Assert.SequenceEqual([true, false, true], await AnalysedAsync(fx, a, b, c));
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user