Add progress to campaign entity
This commit is contained in:
@ -20,6 +20,8 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
|||||||
|
|
||||||
private RegistryService? registryService;
|
private RegistryService? registryService;
|
||||||
|
|
||||||
|
protected override int StepCount => Enum.GetValues(typeof(Step)).Length;
|
||||||
|
|
||||||
protected RegistryService RegistryService => registryService ??= scope.ServiceProvider.GetRequiredService<RegistryService>();
|
protected RegistryService RegistryService => registryService ??= scope.ServiceProvider.GetRequiredService<RegistryService>();
|
||||||
|
|
||||||
public override async Task ProcessAsync()
|
public override async Task ProcessAsync()
|
||||||
@ -53,8 +55,7 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
|||||||
{
|
{
|
||||||
await HeadquartersService.SetCampaignStartedAsync(context, campaign.Id);
|
await HeadquartersService.SetCampaignStartedAsync(context, campaign.Id);
|
||||||
|
|
||||||
campaign.Step = (int)Step.ExecutionWait;
|
await ProgressStepAsync(context, (int)Step.ExecutionWait);
|
||||||
await HeadquartersService.UpdateCampaignStepAsync(context, campaign);
|
|
||||||
|
|
||||||
var registryCount = await RegistryService.GetRegistryCountAsync(context, true);
|
var registryCount = await RegistryService.GetRegistryCountAsync(context, true);
|
||||||
operations = await HeadquartersService.InitiateOperationsAsync(context, registryCount, campaign.Id, Operation.OperationType.NsiCommon_ExportNsiItem_15_7_0_1);
|
operations = await HeadquartersService.InitiateOperationsAsync(context, registryCount, campaign.Id, Operation.OperationType.NsiCommon_ExportNsiItem_15_7_0_1);
|
||||||
@ -85,8 +86,7 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
|||||||
{
|
{
|
||||||
if (operationExecutionState.HasCampaignOperation(campaign.Id)) return;
|
if (operationExecutionState.HasCampaignOperation(campaign.Id)) return;
|
||||||
|
|
||||||
campaign.Step = (int)Step.ResultWait;
|
await ProgressStepAsync((int)Step.ResultWait);
|
||||||
await HeadquartersService.UpdateCampaignStepAsync(campaign);
|
|
||||||
|
|
||||||
var operations = await HeadquartersService.GetOperationsAsync(campaign.Id);
|
var operations = await HeadquartersService.GetOperationsAsync(campaign.Id);
|
||||||
foreach (var operation in operations)
|
foreach (var operation in operations)
|
||||||
@ -109,8 +109,7 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
|||||||
using var transaction = await context.Database.BeginTransactionAsync();
|
using var transaction = await context.Database.BeginTransactionAsync();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
campaign.Step = (int)Step.End;
|
await ProgressStepAsync(context, (int)Step.End);
|
||||||
await HeadquartersService.UpdateCampaignStepAsync(context, campaign);
|
|
||||||
|
|
||||||
await HeadquartersService.SetCampaignEndedAsync(context, campaign.Id);
|
await HeadquartersService.SetCampaignEndedAsync(context, campaign.Id);
|
||||||
|
|
||||||
|
|||||||
@ -20,6 +20,8 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
|||||||
|
|
||||||
private RegistryService? registryService;
|
private RegistryService? registryService;
|
||||||
|
|
||||||
|
protected override int StepCount => Enum.GetValues(typeof(Step)).Length;
|
||||||
|
|
||||||
protected RegistryService RegistryService => registryService ??= scope.ServiceProvider.GetRequiredService<RegistryService>();
|
protected RegistryService RegistryService => registryService ??= scope.ServiceProvider.GetRequiredService<RegistryService>();
|
||||||
|
|
||||||
public override async Task ProcessAsync()
|
public override async Task ProcessAsync()
|
||||||
@ -53,8 +55,7 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
|||||||
{
|
{
|
||||||
await HeadquartersService.SetCampaignStartedAsync(context, campaign.Id);
|
await HeadquartersService.SetCampaignStartedAsync(context, campaign.Id);
|
||||||
|
|
||||||
campaign.Step = (int)Step.ExecutionWait;
|
await ProgressStepAsync(context, (int)Step.ExecutionWait);
|
||||||
await HeadquartersService.UpdateCampaignStepAsync(context, campaign);
|
|
||||||
|
|
||||||
var registryCount = await RegistryService.GetRegistryCountAsync(context, false);
|
var registryCount = await RegistryService.GetRegistryCountAsync(context, false);
|
||||||
operations = await HeadquartersService.InitiateOperationsAsync(context, registryCount, campaign.Id, Operation.OperationType.Nsi_ExportNsiItem_15_7_0_1);
|
operations = await HeadquartersService.InitiateOperationsAsync(context, registryCount, campaign.Id, Operation.OperationType.Nsi_ExportNsiItem_15_7_0_1);
|
||||||
@ -85,8 +86,7 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
|||||||
{
|
{
|
||||||
if (operationExecutionState.HasCampaignOperation(campaign.Id)) return;
|
if (operationExecutionState.HasCampaignOperation(campaign.Id)) return;
|
||||||
|
|
||||||
campaign.Step = (int)Step.ResultWait;
|
await ProgressStepAsync((int)Step.ResultWait);
|
||||||
await HeadquartersService.UpdateCampaignStepAsync(campaign);
|
|
||||||
|
|
||||||
var operations = await HeadquartersService.GetOperationsAsync(campaign.Id);
|
var operations = await HeadquartersService.GetOperationsAsync(campaign.Id);
|
||||||
foreach (var operation in operations)
|
foreach (var operation in operations)
|
||||||
@ -109,8 +109,7 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
|||||||
using var transaction = await context.Database.BeginTransactionAsync();
|
using var transaction = await context.Database.BeginTransactionAsync();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
campaign.Step = (int)Step.End;
|
await ProgressStepAsync(context, (int)Step.End);
|
||||||
await HeadquartersService.UpdateCampaignStepAsync(context, campaign);
|
|
||||||
|
|
||||||
await HeadquartersService.SetCampaignEndedAsync(context, campaign.Id);
|
await HeadquartersService.SetCampaignEndedAsync(context, campaign.Id);
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,8 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
|||||||
|
|
||||||
protected HeadquartersService HeadquartersService => headquartersService ??= scope.ServiceProvider.GetRequiredService<HeadquartersService>();
|
protected HeadquartersService HeadquartersService => headquartersService ??= scope.ServiceProvider.GetRequiredService<HeadquartersService>();
|
||||||
|
|
||||||
|
protected abstract int StepCount { get; }
|
||||||
|
|
||||||
public Campaign Campaign => campaign;
|
public Campaign Campaign => campaign;
|
||||||
|
|
||||||
public IManager.ManagerState State { get; protected set; } = IManager.ManagerState.Created;
|
public IManager.ManagerState State { get; protected set; } = IManager.ManagerState.Created;
|
||||||
@ -31,5 +33,18 @@ namespace Hcs.WebApp.BackgroundServices.CampaignManagers
|
|||||||
|
|
||||||
State = IManager.ManagerState.Ended;
|
State = IManager.ManagerState.Ended;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected async Task ProgressStepAsync(int step)
|
||||||
|
{
|
||||||
|
using var context = HeadquartersService.GetNewContext();
|
||||||
|
await ProgressStepAsync(context, step);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async Task ProgressStepAsync(HcsDbContext context, int step)
|
||||||
|
{
|
||||||
|
campaign.Step = step;
|
||||||
|
campaign.Progress = (step + 1) / StepCount;
|
||||||
|
await HeadquartersService.UpdateCampaignStepAndProgressAsync(context, campaign);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,6 +41,11 @@
|
|||||||
<Columns>
|
<Columns>
|
||||||
<RadzenDataGridColumn TItem="Campaign" Property="Id" Title="ID" SortOrder="SortOrder.Descending" Resizable="false" Width="100px" MaxWidth="100px" />
|
<RadzenDataGridColumn TItem="Campaign" Property="Id" Title="ID" SortOrder="SortOrder.Descending" Resizable="false" Width="100px" MaxWidth="100px" />
|
||||||
<RadzenDataGridColumn TItem="Campaign" Property="Type" Title="Тип кампании" />
|
<RadzenDataGridColumn TItem="Campaign" Property="Type" Title="Тип кампании" />
|
||||||
|
<RadzenDataGridColumn Title="Состояние" Filterable="false" Sortable="false" Resizable="false" Width="70px" MaxWidth="70px">
|
||||||
|
<Template Context="campaign">
|
||||||
|
<RadzenProgressBar ProgressBarStyle="@(campaign.EndedAt.HasValue ? (string.IsNullOrEmpty(campaign.FailureReason) ? ProgressBarStyle.Success : ProgressBarStyle.Danger) : ProgressBarStyle.Primary)" Value="@campaign.Progress" ShowValue="false" />
|
||||||
|
</Template>
|
||||||
|
</RadzenDataGridColumn>
|
||||||
<RadzenDataGridColumn TItem="Campaign" Property="CreatedAt" Title="Дата создания" Resizable="false" Width="150px" MaxWidth="150px" />
|
<RadzenDataGridColumn TItem="Campaign" Property="CreatedAt" Title="Дата создания" Resizable="false" Width="150px" MaxWidth="150px" />
|
||||||
<RadzenDataGridColumn TItem="Campaign" Property="StartedAt" Title="Дата начала" Resizable="false" Width="150px" MaxWidth="150px" />
|
<RadzenDataGridColumn TItem="Campaign" Property="StartedAt" Title="Дата начала" Resizable="false" Width="150px" MaxWidth="150px" />
|
||||||
<RadzenDataGridColumn TItem="Campaign" Property="StartedAt" Title="Дата окончания" Resizable="false" Width="150px" MaxWidth="150px" />
|
<RadzenDataGridColumn TItem="Campaign" Property="StartedAt" Title="Дата окончания" Resizable="false" Width="150px" MaxWidth="150px" />
|
||||||
|
|||||||
@ -28,6 +28,8 @@ namespace Hcs.WebApp.Data.Hcs
|
|||||||
|
|
||||||
public int Step { get; set; } = 0;
|
public int Step { get; set; } = 0;
|
||||||
|
|
||||||
|
public int Progress { get; set; } = 0;
|
||||||
|
|
||||||
public string? FailureReason { get; set; }
|
public string? FailureReason { get; set; }
|
||||||
|
|
||||||
public virtual ICollection<Operation>? Operations { get; set; } = null;
|
public virtual ICollection<Operation>? Operations { get; set; } = null;
|
||||||
|
|||||||
@ -169,18 +169,19 @@ namespace Hcs.WebApp.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateCampaignStepAsync(Campaign campaign)
|
public async Task UpdateCampaignStepAndProgressAsync(Campaign campaign)
|
||||||
{
|
{
|
||||||
using var context = GetNewContext();
|
using var context = GetNewContext();
|
||||||
await UpdateCampaignStepAsync(context, campaign);
|
await UpdateCampaignStepAndProgressAsync(context, campaign);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateCampaignStepAsync(HcsDbContext context, Campaign campaign)
|
public async Task UpdateCampaignStepAndProgressAsync(HcsDbContext context, Campaign campaign)
|
||||||
{
|
{
|
||||||
var targetCampaign = await context.Campaigns.FirstOrDefaultAsync(x => x.Id == campaign.Id);
|
var targetCampaign = await context.Campaigns.FirstOrDefaultAsync(x => x.Id == campaign.Id);
|
||||||
if (targetCampaign != null)
|
if (targetCampaign != null)
|
||||||
{
|
{
|
||||||
targetCampaign.Step = campaign.Step;
|
targetCampaign.Step = campaign.Step;
|
||||||
|
targetCampaign.Progress = campaign.Progress;
|
||||||
|
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user