Use operations kind

This commit is contained in:
2025-11-17 15:43:58 +09:00
parent a4055bee7e
commit 88f4d8ba2d
4 changed files with 25 additions and 11 deletions

View File

@ -22,7 +22,7 @@ namespace Hcs.WebApp.BackgroundServices
using var scope = scopeFactory.CreateScope(); using var scope = scopeFactory.CreateScope();
var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>(); var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>();
var operations = await headquartersService.GetResultWaitingOperationsAsync(); var operations = await headquartersService.GetNotCompletedParseOperationsAsync();
foreach (var operation in operations) foreach (var operation in operations)
{ {
state.EnqueueOperation(operation); state.EnqueueOperation(operation);

View File

@ -75,7 +75,7 @@ namespace Hcs.WebApp.BackgroundServices
using var scope = scopeFactory.CreateScope(); using var scope = scopeFactory.CreateScope();
var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>(); var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>();
var operations = await headquartersService.GetNotExecutedOperationsAsync(); var operations = await headquartersService.GetNotExecutedRemoteOperationsAsync();
foreach (var operation in operations) foreach (var operation in operations)
{ {
state.EnqueueOperation(operation); state.EnqueueOperation(operation);

View File

@ -118,7 +118,7 @@ namespace Hcs.WebApp.BackgroundServices
using var scope = scopeFactory.CreateScope(); using var scope = scopeFactory.CreateScope();
var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>(); var headquartersService = scope.ServiceProvider.GetRequiredService<HeadquartersService>();
var operations = await headquartersService.GetResultWaitingOperationsAsync(); var operations = await headquartersService.GetResultWaitingRemoteOperationsAsync();
foreach (var operation in operations) foreach (var operation in operations)
{ {
state.EnqueueOperation(operation); state.EnqueueOperation(operation);

View File

@ -25,20 +25,34 @@ namespace Hcs.WebApp.Services
select campaign).ToListAsync(); select campaign).ToListAsync();
} }
public async Task<IEnumerable<Operation>> GetNotExecutedOperationsAsync() public async Task<IEnumerable<Operation>> GetNotExecutedRemoteOperationsAsync()
{ {
using var context = GetNewContext(); using var context = GetNewContext();
return await (from operation in context.Operations var query = from operation in context.Operations
where string.IsNullOrEmpty(operation.MessageGuid) && !operation.EndedAt.HasValue where string.IsNullOrEmpty(operation.MessageGuid) && !operation.EndedAt.HasValue
select operation).ToListAsync(); select operation;
var result = await query.ToListAsync();
return result.Where(x => x.Kind == Operation.OperationKind.Remote);
} }
public async Task<IEnumerable<Operation>> GetResultWaitingOperationsAsync() public async Task<IEnumerable<Operation>> GetResultWaitingRemoteOperationsAsync()
{ {
using var context = GetNewContext(); using var context = GetNewContext();
return await (from operation in context.Operations var query = from operation in context.Operations
where !string.IsNullOrEmpty(operation.MessageGuid) && !operation.EndedAt.HasValue where !string.IsNullOrEmpty(operation.MessageGuid) && !operation.EndedAt.HasValue
select operation).ToListAsync(); select operation;
var result = await query.ToListAsync();
return result.Where(x => x.Kind == Operation.OperationKind.Remote);
}
public async Task<IEnumerable<Operation>> GetNotCompletedParseOperationsAsync()
{
using var context = GetNewContext();
var query = from operation in context.Operations
where !operation.EndedAt.HasValue
select operation;
var result = await query.ToListAsync();
return result.Where(x => x.Kind == Operation.OperationKind.Parse);
} }
public async Task<ICollection<Operation>> GetOperationsAsync() public async Task<ICollection<Operation>> GetOperationsAsync()