Skip to content
Merged

Dev #2394

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public async Task<decimal> GetTotalPaymentRequestAmountByCorrelationIdAsync(Guid
.Where(p => p.Status != PaymentRequestStatus.L1Declined
&& p.Status != PaymentRequestStatus.L2Declined
&& p.Status != PaymentRequestStatus.L3Declined
&& p.InvoiceStatus != CasPaymentRequestStatus.Cancelled
&& p.InvoiceStatus != CasPaymentRequestStatus.NotFound
&& p.InvoiceStatus != CasPaymentRequestStatus.ErrorFromCas)
.GroupBy(p => p.CorrelationId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using Unity.GrantManager.GrantApplications;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Uow;

namespace Unity.GrantManager.GrantApplications.Automation.BackgroundJobs;

Expand Down Expand Up @@ -49,6 +50,40 @@ public static async Task MarkFailedAsync(
await generationRequestRepository.UpdateAsync(request, autoSave: true);
}

public static async Task MarkRunningInNewUowAsync(
IUnitOfWorkManager unitOfWorkManager,
IRepository<AIGenerationRequest, Guid> generationRequestRepository,
string requestKey)
{
using var uow = unitOfWorkManager.Begin(requiresNew: true, isTransactional: false);
var request = await GetLatestRequestAsync(generationRequestRepository, x => x.RequestKey == requestKey);
await MarkRunningAsync(generationRequestRepository, request);
await uow.CompleteAsync();
}

public static async Task MarkCompletedInNewUowAsync(
IUnitOfWorkManager unitOfWorkManager,
IRepository<AIGenerationRequest, Guid> generationRequestRepository,
string requestKey)
{
using var uow = unitOfWorkManager.Begin(requiresNew: true, isTransactional: false);
var request = await GetLatestRequestAsync(generationRequestRepository, x => x.RequestKey == requestKey);
await MarkCompletedAsync(generationRequestRepository, request);
await uow.CompleteAsync();
}

public static async Task MarkFailedInNewUowAsync(
IUnitOfWorkManager unitOfWorkManager,
IRepository<AIGenerationRequest, Guid> generationRequestRepository,
string requestKey,
string? failureReason)
{
using var uow = unitOfWorkManager.Begin(requiresNew: true, isTransactional: false);
var request = await GetLatestRequestAsync(generationRequestRepository, x => x.RequestKey == requestKey);
await MarkFailedAsync(generationRequestRepository, request, failureReason);
await uow.CompleteAsync();
}

public static async Task<AIGenerationRequest?> GetLatestRequestAsync(
IRepository<AIGenerationRequest, Guid> generationRequestRepository,
Expression<Func<AIGenerationRequest, bool>> predicate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,33 @@
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Uow;

namespace Unity.GrantManager.GrantApplications.Automation.BackgroundJobs;

public class GenerateApplicationAnalysisJob(
IApplicationAnalysisService applicationAnalysisService,
IRepository<AIGenerationRequest, Guid> generationRequestRepository,
ICurrentTenant currentTenant,
IUnitOfWorkManager unitOfWorkManager,
ILogger<GenerateApplicationAnalysisJob> logger) : AsyncBackgroundJob<GenerateApplicationAnalysisBackgroundJobArgs>, ITransientDependency
{
public override async Task ExecuteAsync(GenerateApplicationAnalysisBackgroundJobArgs args)
{
using (currentTenant.Change(args.TenantId))
{
var request = await AIGenerationRequestJobHelper.GetLatestRequestAsync(generationRequestRepository, x => x.RequestKey == args.RequestKey);
await AIGenerationRequestJobHelper.MarkRunningAsync(generationRequestRepository, request);
await AIGenerationRequestJobHelper.MarkRunningInNewUowAsync(unitOfWorkManager, generationRequestRepository, args.RequestKey);
try
{
logger.LogInformation("Executing AI application analysis job for application {ApplicationId}.", args.ApplicationId);
await applicationAnalysisService.RegenerateAndSaveAsync(args.ApplicationId, args.PromptVersion);
logger.LogInformation("Completed AI application analysis job for application {ApplicationId}.", args.ApplicationId);

await AIGenerationRequestJobHelper.MarkCompletedAsync(generationRequestRepository, request);
await AIGenerationRequestJobHelper.MarkCompletedInNewUowAsync(unitOfWorkManager, generationRequestRepository, args.RequestKey);
}
catch (Exception ex)
{
await AIGenerationRequestJobHelper.MarkFailedAsync(generationRequestRepository, request, ex.Message);
await AIGenerationRequestJobHelper.MarkFailedInNewUowAsync(unitOfWorkManager, generationRequestRepository, args.RequestKey, ex.Message);
throw;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,32 @@
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Uow;

namespace Unity.GrantManager.GrantApplications.Automation.BackgroundJobs;

public class GenerateApplicationScoringJob(
IApplicationScoringAppService applicationScoringAppService,
IRepository<AIGenerationRequest, Guid> generationRequestRepository,
ICurrentTenant currentTenant,
IUnitOfWorkManager unitOfWorkManager,
ILogger<GenerateApplicationScoringJob> logger) : AsyncBackgroundJob<GenerateApplicationScoringBackgroundJobArgs>, ITransientDependency
{
public override async Task ExecuteAsync(GenerateApplicationScoringBackgroundJobArgs args)
{
using (currentTenant.Change(args.TenantId))
{
var request = await AIGenerationRequestJobHelper.GetLatestRequestAsync(generationRequestRepository, x => x.RequestKey == args.RequestKey);
await AIGenerationRequestJobHelper.MarkRunningAsync(generationRequestRepository, request);
await AIGenerationRequestJobHelper.MarkRunningInNewUowAsync(unitOfWorkManager, generationRequestRepository, args.RequestKey);
try
{
logger.LogInformation("Executing AI application scoring job for application {ApplicationId}.", args.ApplicationId);
await applicationScoringAppService.GenerateApplicationScoringAsync(args.ApplicationId, args.PromptVersion);
logger.LogInformation("Completed AI application scoring job for application {ApplicationId}.", args.ApplicationId);
await AIGenerationRequestJobHelper.MarkCompletedAsync(generationRequestRepository, request);
await AIGenerationRequestJobHelper.MarkCompletedInNewUowAsync(unitOfWorkManager, generationRequestRepository, args.RequestKey);
}
catch (Exception ex)
{
await AIGenerationRequestJobHelper.MarkFailedAsync(generationRequestRepository, request, ex.Message);
await AIGenerationRequestJobHelper.MarkFailedInNewUowAsync(unitOfWorkManager, generationRequestRepository, args.RequestKey, ex.Message);
throw;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,33 @@
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Uow;

namespace Unity.GrantManager.GrantApplications.Automation.BackgroundJobs;

public class GenerateAttachmentSummaryJob(
IAttachmentSummaryService attachmentSummaryService,
IRepository<AIGenerationRequest, Guid> generationRequestRepository,
ICurrentTenant currentTenant,
IUnitOfWorkManager unitOfWorkManager,
ILogger<GenerateAttachmentSummaryJob> logger) : AsyncBackgroundJob<GenerateAttachmentSummaryBackgroundJobArgs>, ITransientDependency
{
public override async Task ExecuteAsync(GenerateAttachmentSummaryBackgroundJobArgs args)
{
using (currentTenant.Change(args.TenantId))
{
var request = await AIGenerationRequestJobHelper.GetLatestRequestAsync(generationRequestRepository, x => x.RequestKey == args.RequestKey);
await AIGenerationRequestJobHelper.MarkRunningAsync(generationRequestRepository, request);
await AIGenerationRequestJobHelper.MarkRunningInNewUowAsync(unitOfWorkManager, generationRequestRepository, args.RequestKey);
try
{
logger.LogInformation(
"Executing AI attachment summary job for application {ApplicationId}.",
args.ApplicationId);
await attachmentSummaryService.GenerateForApplicationAsync(args.ApplicationId, args.PromptVersion);
await AIGenerationRequestJobHelper.MarkCompletedAsync(generationRequestRepository, request);
await AIGenerationRequestJobHelper.MarkCompletedInNewUowAsync(unitOfWorkManager, generationRequestRepository, args.RequestKey);
}
catch (Exception ex)
{
await AIGenerationRequestJobHelper.MarkFailedAsync(generationRequestRepository, request, ex.Message);
await AIGenerationRequestJobHelper.MarkFailedInNewUowAsync(unitOfWorkManager, generationRequestRepository, args.RequestKey, ex.Message);
throw;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Volo.Abp.EventBus.Local;
using Volo.Abp.Features;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Uow;

namespace Unity.GrantManager.GrantApplications.Automation.BackgroundJobs;

Expand All @@ -25,6 +26,7 @@ public class RunApplicationAIPipelineJob(
ILocalEventBus localEventBus,
IRepository<AIGenerationRequest, Guid> generationRequestRepository,
ICurrentTenant currentTenant,
IUnitOfWorkManager unitOfWorkManager,
ILogger<RunApplicationAIPipelineJob> logger) : AsyncBackgroundJob<RunApplicationAIPipelineJobArgs>, ITransientDependency
{
public override async Task ExecuteAsync(RunApplicationAIPipelineJobArgs args)
Expand All @@ -36,11 +38,7 @@ public override async Task ExecuteAsync(RunApplicationAIPipelineJobArgs args)

using (currentTenant.Change(args.TenantId))
{
var request = await AIGenerationRequestJobHelper.GetLatestRequestAsync(
generationRequestRepository,
x => x.RequestKey == args.RequestKey);

await AIGenerationRequestJobHelper.MarkRunningAsync(generationRequestRepository, request);
await AIGenerationRequestJobHelper.MarkRunningInNewUowAsync(unitOfWorkManager, generationRequestRepository, args.RequestKey);

try
{
Expand All @@ -51,7 +49,7 @@ public override async Task ExecuteAsync(RunApplicationAIPipelineJobArgs args)
if (!attachmentSummariesEnabled && !applicationAnalysisEnabled && !scoringEnabled)
{
logger.LogDebug("All AI features are disabled, skipping queued AI generation for application {ApplicationId}.", args.ApplicationId);
await AIGenerationRequestJobHelper.MarkCompletedAsync(generationRequestRepository, request);
await AIGenerationRequestJobHelper.MarkCompletedInNewUowAsync(unitOfWorkManager, generationRequestRepository, args.RequestKey);
return;
}

Expand Down Expand Up @@ -114,11 +112,11 @@ await localEventBus.PublishAsync(new ApplicationAIScoringGeneratedEvent
throw analysisException;
}

await AIGenerationRequestJobHelper.MarkCompletedAsync(generationRequestRepository, request);
await AIGenerationRequestJobHelper.MarkCompletedInNewUowAsync(unitOfWorkManager, generationRequestRepository, args.RequestKey);
}
catch (Exception ex)
{
await AIGenerationRequestJobHelper.MarkFailedAsync(generationRequestRepository, request, ex.Message);
await AIGenerationRequestJobHelper.MarkFailedInNewUowAsync(unitOfWorkManager, generationRequestRepository, args.RequestKey, ex.Message);
throw;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,10 @@

.ai-generate-btn {
height: 2.25rem;
min-width: 8rem;
}

.ai-generate-btn.btn-sm {
height: 2rem;
min-width: 7rem;
}

.ai-generate-btn .spinner-border-sm {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Volo.Abp.EventBus.Local;
using Volo.Abp.Features;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Uow;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -78,7 +79,7 @@ await localEventBus.Received(1).PublishAsync(
Arg.Is<Automation.Events.ApplicationAIScoringGeneratedEvent>(x => x.ApplicationId == request.ApplicationId));
}

private static RunApplicationAIPipelineJob BuildJob(
private RunApplicationAIPipelineJob BuildJob(
IFeatureChecker featureChecker,
IRepository<AIGenerationRequest, Guid> generationRequestRepository,
ILocalEventBus? localEventBus = null,
Expand All @@ -95,6 +96,7 @@ private static RunApplicationAIPipelineJob BuildJob(
localEventBus ?? Substitute.For<ILocalEventBus>(),
generationRequestRepository,
Substitute.For<ICurrentTenant>(),
GetRequiredService<IUnitOfWorkManager>(),
NullLogger<RunApplicationAIPipelineJob>.Instance);
}

Expand Down
Loading