Refactor envelope processing for per-item error handling

Move per-envelope logic in FinalizeDocumentJob into its own try-catch block within the foreach loop. This ensures that exceptions in processing one envelope do not halt the processing of others, improving robustness and fault tolerance. Removed the outer try-catch-finally block and updated logging to reflect per-envelope and overall job status.
This commit is contained in:
2026-03-09 09:42:55 +01:00
parent d6e2690bb8
commit 9fd7a68798

View File

@@ -43,8 +43,6 @@ public class FinalizeDocumentJob(IOptions<WorkerOptions> options, IConfiguration
var jobId = typeof(FinalizeDocumentJob).FullName; var jobId = typeof(FinalizeDocumentJob).FullName;
logger.LogDebug("Starting job {jobId}", jobId); logger.LogDebug("Starting job {jobId}", jobId);
try
{
_config = await mediator.Send(new ReadDefaultConfigQuery(), cancel); _config = await mediator.Send(new ReadDefaultConfigQuery(), cancel);
var envelopes = await envRepo var envelopes = await envRepo
@@ -145,26 +143,6 @@ public class FinalizeDocumentJob(IOptions<WorkerOptions> options, IConfiguration
logger.LogDebug("Completed job {jobId} successfully!", jobId); logger.LogDebug("Completed job {jobId} successfully!", jobId);
} }
catch (MergeDocumentException ex)
{
logger.LogWarning("Certificate Document job failed at step: Merging documents!");
logger.LogError(ex);
}
catch (ExportDocumentException ex)
{
logger.LogWarning("Certificate Document job failed at step: Exporting document!");
logger.LogError(ex);
}
catch (Exception ex)
{
logger.LogWarning("Certificate Document job failed!");
logger.LogError(ex);
}
finally
{
logger.LogDebug("Job execution for [{jobId}] ended", jobId);
}
}
private void UpdateFileDb(string filePath, long envelopeId) private void UpdateFileDb(string filePath, long envelopeId)
{ {