This commit is contained in:
2025-11-09 02:08:31 +07:00
parent 1ed58d1a98
commit 7dba29c66f
57 changed files with 8362 additions and 359 deletions

View File

@@ -0,0 +1,157 @@
#nullable enable
using System.ComponentModel.DataAnnotations;
using static Managing.Common.Enums;
namespace Managing.Domain.Backtests;
/// <summary>
/// Represents a single backtest job in the queue system.
/// Can be a standalone backtest or part of a bundle backtest request.
/// </summary>
public class BacktestJob
{
public BacktestJob()
{
Id = Guid.NewGuid();
CreatedAt = DateTime.UtcNow;
Status = BacktestJobStatus.Pending;
ProgressPercentage = 0;
}
/// <summary>
/// Unique identifier for the job
/// </summary>
[Required]
public Guid Id { get; set; }
/// <summary>
/// Optional bundle request ID if this job is part of a bundle
/// </summary>
public Guid? BundleRequestId { get; set; }
/// <summary>
/// User ID who created this job
/// </summary>
[Required]
public int UserId { get; set; }
/// <summary>
/// Current status of the job
/// </summary>
[Required]
public BacktestJobStatus Status { get; set; }
/// <summary>
/// Priority of the job (higher = more important)
/// </summary>
[Required]
public int Priority { get; set; } = 0;
/// <summary>
/// Serialized TradingBotConfig JSON
/// </summary>
[Required]
public string ConfigJson { get; set; } = string.Empty;
/// <summary>
/// Start date for the backtest
/// </summary>
[Required]
public DateTime StartDate { get; set; }
/// <summary>
/// End date for the backtest
/// </summary>
[Required]
public DateTime EndDate { get; set; }
/// <summary>
/// Progress percentage (0-100)
/// </summary>
[Required]
public int ProgressPercentage { get; set; }
/// <summary>
/// Worker ID that has claimed this job
/// </summary>
public string? AssignedWorkerId { get; set; }
/// <summary>
/// Last heartbeat timestamp from the assigned worker
/// </summary>
public DateTime? LastHeartbeat { get; set; }
/// <summary>
/// When the job was created
/// </summary>
[Required]
public DateTime CreatedAt { get; set; }
/// <summary>
/// When the job started processing
/// </summary>
public DateTime? StartedAt { get; set; }
/// <summary>
/// When the job completed (successfully or failed)
/// </summary>
public DateTime? CompletedAt { get; set; }
/// <summary>
/// Serialized LightBacktest result JSON (when completed)
/// </summary>
public string? ResultJson { get; set; }
/// <summary>
/// Error message if the job failed
/// </summary>
public string? ErrorMessage { get; set; }
/// <summary>
/// Request ID to associate with the backtest result (for grouping)
/// </summary>
public string? RequestId { get; set; }
/// <summary>
/// Type of job (Backtest or GeneticBacktest)
/// </summary>
[Required]
public JobType JobType { get; set; } = JobType.Backtest;
/// <summary>
/// Optional genetic request ID if this is a genetic backtest job
/// </summary>
public string? GeneticRequestId { get; set; }
}
/// <summary>
/// Status of a backtest job
/// </summary>
public enum BacktestJobStatus
{
/// <summary>
/// Job is pending and waiting to be claimed by a worker
/// </summary>
Pending,
/// <summary>
/// Job is currently being processed by a worker
/// </summary>
Running,
/// <summary>
/// Job completed successfully
/// </summary>
Completed,
/// <summary>
/// Job failed with an error
/// </summary>
Failed,
/// <summary>
/// Job was cancelled
/// </summary>
Cancelled
}