Add jobs
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Text.Json;
|
||||
using Managing.Api.Models.Requests;
|
||||
using Managing.Api.Models.Responses;
|
||||
using Managing.Application.Abstractions.Repositories;
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Application.Abstractions.Shared;
|
||||
using Managing.Application.Hubs;
|
||||
@@ -34,6 +35,7 @@ public class BacktestController : BaseController
|
||||
private readonly IAccountService _accountService;
|
||||
private readonly IMoneyManagementService _moneyManagementService;
|
||||
private readonly IGeneticService _geneticService;
|
||||
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BacktestController"/> class.
|
||||
@@ -51,13 +53,15 @@ public class BacktestController : BaseController
|
||||
IAccountService accountService,
|
||||
IMoneyManagementService moneyManagementService,
|
||||
IGeneticService geneticService,
|
||||
IUserService userService) : base(userService)
|
||||
IUserService userService,
|
||||
IServiceScopeFactory serviceScopeFactory) : base(userService)
|
||||
{
|
||||
_hubContext = hubContext;
|
||||
_backtester = backtester;
|
||||
_accountService = accountService;
|
||||
_moneyManagementService = moneyManagementService;
|
||||
_geneticService = geneticService;
|
||||
_serviceScopeFactory = serviceScopeFactory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -788,6 +792,51 @@ public class BacktestController : BaseController
|
||||
return Ok(new { Unsubscribed = true, RequestId = requestId });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the status of a bundle backtest request, aggregating all job statuses.
|
||||
/// </summary>
|
||||
/// <param name="bundleRequestId">The bundle request ID</param>
|
||||
/// <returns>The bundle status with aggregated job statistics</returns>
|
||||
[HttpGet]
|
||||
[Route("Bundle/{bundleRequestId}/Status")]
|
||||
public async Task<ActionResult<BundleBacktestStatusResponse>> GetBundleStatus(string bundleRequestId)
|
||||
{
|
||||
if (!Guid.TryParse(bundleRequestId, out var bundleGuid))
|
||||
{
|
||||
return BadRequest("Invalid bundle request ID format. Must be a valid GUID.");
|
||||
}
|
||||
|
||||
var user = await GetUser();
|
||||
var bundleRequest = _backtester.GetBundleBacktestRequestByIdForUser(user, bundleGuid);
|
||||
|
||||
if (bundleRequest == null)
|
||||
{
|
||||
return NotFound($"Bundle backtest request with ID {bundleRequestId} not found.");
|
||||
}
|
||||
|
||||
// Get all jobs for this bundle
|
||||
using var serviceScope = _serviceScopeFactory.CreateScope();
|
||||
var jobRepository = serviceScope.ServiceProvider.GetRequiredService<IBacktestJobRepository>();
|
||||
var jobs = await jobRepository.GetByBundleRequestIdAsync(bundleGuid);
|
||||
|
||||
var response = new BundleBacktestStatusResponse
|
||||
{
|
||||
BundleRequestId = bundleGuid,
|
||||
Status = bundleRequest.Status.ToString(),
|
||||
TotalJobs = jobs.Count(),
|
||||
CompletedJobs = jobs.Count(j => j.Status == BacktestJobStatus.Completed),
|
||||
FailedJobs = jobs.Count(j => j.Status == BacktestJobStatus.Failed),
|
||||
RunningJobs = jobs.Count(j => j.Status == BacktestJobStatus.Running),
|
||||
PendingJobs = jobs.Count(j => j.Status == BacktestJobStatus.Pending),
|
||||
ProgressPercentage = bundleRequest.ProgressPercentage,
|
||||
CreatedAt = bundleRequest.CreatedAt,
|
||||
CompletedAt = bundleRequest.CompletedAt,
|
||||
ErrorMessage = bundleRequest.ErrorMessage
|
||||
};
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs a genetic algorithm optimization with the specified configuration.
|
||||
/// This endpoint saves the genetic request to the database and returns the request ID.
|
||||
|
||||
Reference in New Issue
Block a user