Compare commits
4 Commits
f04385a03c
...
cc4a7d8c20
| Author | SHA1 | Date | |
|---|---|---|---|
| cc4a7d8c20 | |||
| 0b8068f926 | |||
| 9fd7a68798 | |||
| d6e2690bb8 |
@@ -1,30 +1,34 @@
|
|||||||
|
using DigitalData.Core.Abstraction.Application.Repository;
|
||||||
using EnvelopeGenerator.Domain.Entities;
|
using EnvelopeGenerator.Domain.Entities;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.ServiceHost.Jobs;
|
namespace EnvelopeGenerator.ServiceHost.Jobs;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// migrate from EnvelopeGenerator.CommonServices.Services.ActionService
|
||||||
|
/// </summary>
|
||||||
[Obsolete("This is a placeholder service added by copilot. Migrate the actual logic from CommonServices.Jobs")]
|
[Obsolete("This is a placeholder service added by copilot. Migrate the actual logic from CommonServices.Jobs")]
|
||||||
public class ActionService
|
public class ActionService(IRepository<History> histRepo)
|
||||||
{
|
{
|
||||||
[Obsolete("This is a placeholder service added by copilot. Migrate the actual logic from CommonServices.Jobs")]
|
[Obsolete("This is a placeholder service added by copilot. Migrate the actual logic from CommonServices.Jobs")]
|
||||||
public bool CreateReport(Envelope envelope)
|
public bool CreateReport(Envelope envelope, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Obsolete("This is a placeholder service added by copilot. Migrate the actual logic from CommonServices.Jobs")]
|
[Obsolete("This is a placeholder service added by copilot. Migrate the actual logic from CommonServices.Jobs")]
|
||||||
public bool FinalizeEnvelope(Envelope envelope)
|
public bool FinalizeEnvelope(Envelope envelope, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Obsolete("This is a placeholder service added by copilot. Migrate the actual logic from CommonServices.Jobs")]
|
[Obsolete("This is a placeholder service added by copilot. Migrate the actual logic from CommonServices.Jobs")]
|
||||||
public bool CompleteEnvelope(Envelope envelope)
|
public bool CompleteEnvelope(Envelope envelope, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Obsolete("This is a placeholder service added by copilot. Migrate the actual logic from CommonServices.Jobs")]
|
[Obsolete("This is a placeholder service added by copilot. Migrate the actual logic from CommonServices.Jobs")]
|
||||||
public bool CompleteEnvelope(Envelope envelope, Receiver receiver)
|
public bool CompleteEnvelope(Envelope envelope, Receiver receiver, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,48 +43,30 @@ 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
|
|
||||||
{
|
|
||||||
logger.LogDebug("Loading Configuration..");
|
|
||||||
_config = await mediator.Send(new ReadDefaultConfigQuery(), cancel);
|
_config = await mediator.Send(new ReadDefaultConfigQuery(), cancel);
|
||||||
|
|
||||||
logger.LogDebug("DocumentPath: [{documentPath}]", _config.DocumentPath);
|
var envelopes = await envRepo
|
||||||
logger.LogDebug("ExportPath: [{exportPath}]", _config.ExportPath);
|
.Where(e => e.Status == EnvelopeStatus.EnvelopeCompletelySigned
|
||||||
|
&& e.ChangedWhen.HasValue
|
||||||
|
&& EF.Functions.DateDiffMinute(e.ChangedWhen.Value, DateTime.Now) >= CompleteWaitTime)
|
||||||
|
.OrderBy(e => e.Id)
|
||||||
|
.ToListAsync(cancel);
|
||||||
|
|
||||||
var completeStatus = EnvelopeStatus.EnvelopeCompletelySigned;
|
if (envelopes.Count > 0)
|
||||||
var sql = $"SELECT * FROM TBSIG_ENVELOPE WHERE STATUS = {completeStatus} AND DATEDIFF(minute, CHANGED_WHEN, GETDATE()) >= {CompleteWaitTime} ORDER BY GUID";
|
logger.LogInformation("Found [{count}] completed envelopes.", envelopes.Count);
|
||||||
var table = _database.GetDatatable(sql);
|
|
||||||
|
|
||||||
var envelopeIds = table.Rows.Cast<DataRow>()
|
var total = envelopes.Count;
|
||||||
.Select(r => r.Field<int>("GUID"))
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
if (envelopeIds.Count > 0)
|
|
||||||
{
|
|
||||||
logger.LogInformation("Found [{count}] completed envelopes.", envelopeIds.Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
var total = envelopeIds.Count;
|
|
||||||
var current = 1;
|
var current = 1;
|
||||||
|
|
||||||
foreach (var id in envelopeIds)
|
foreach (var envelope in envelopes)
|
||||||
{
|
{
|
||||||
logger.LogInformation("Finalizing Envelope [{id}] ({current}/{total})", id, current, total);
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var envelope = await envRepo.Where(e => e.Id == id).SingleOrDefaultAsync(cancel);
|
var envelopeData = GetEnvelopeData(envelope.Id);
|
||||||
if (envelope is null)
|
|
||||||
{
|
|
||||||
logger.LogWarning("Envelope could not be loaded for Id [{id}]!", id);
|
|
||||||
throw new ArgumentNullException(nameof(EnvelopeData));
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.LogDebug("Loading Envelope Data..");
|
|
||||||
var envelopeData = GetEnvelopeData(id);
|
|
||||||
|
|
||||||
if (envelopeData is null)
|
if (envelopeData is null)
|
||||||
{
|
{
|
||||||
logger.LogWarning("EnvelopeData could not be loaded for Id [{id}]!", id);
|
logger.LogWarning("EnvelopeData could not be loaded for Id [{id}]!", envelope.Id);
|
||||||
throw new ArgumentNullException(nameof(EnvelopeData));
|
throw new ArgumentNullException(nameof(EnvelopeData));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,35 +134,15 @@ public class FinalizeDocumentJob(IOptions<WorkerOptions> options, IConfiguration
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.LogError(ex);
|
logger.LogError(ex);
|
||||||
logger.LogWarning(ex, "Unhandled exception while working envelope [{id}]", id);
|
logger.LogWarning(ex, "Unhandled exception while working envelope [{id}]", envelope.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
current += 1;
|
current += 1;
|
||||||
logger.LogInformation("Envelope [{id}] finalized!", id);
|
logger.LogInformation("Envelope [{id}] finalized!", envelope.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user