Improve workers for backtests

This commit is contained in:
2025-11-10 01:44:33 +07:00
parent 97f2b8229b
commit 7e52b7a734
18 changed files with 740 additions and 144 deletions

View File

@@ -62,6 +62,24 @@ public interface IJobRepository
/// </summary>
Task<IEnumerable<Job>> GetByGeneticRequestIdAsync(string geneticRequestId);
/// <summary>
/// Gets running job counts per user for a specific job type across all workers (global limit per user)
/// </summary>
/// <param name="workerId">The ID of the worker (kept for interface compatibility, not used for filtering)</param>
/// <param name="jobType">The job type to filter by</param>
/// <returns>Dictionary mapping UserId to count of running jobs</returns>
Task<Dictionary<int, int>> GetRunningJobCountsByUserIdAsync(string workerId, JobType jobType);
/// <summary>
/// Claims a random available job, atomically excluding users that have reached their capacity.
/// The capacity check happens within the SQL query using a subquery, ensuring thread-safety across multiple workers.
/// Returns null if no jobs are available.
/// </summary>
/// <param name="workerId">The ID of the worker claiming the job</param>
/// <param name="jobType">The job type to claim</param>
/// <param name="maxConcurrentPerUser">Maximum concurrent jobs allowed per user</param>
Task<Job?> ClaimRandomJobAsync(string workerId, JobType jobType, int maxConcurrentPerUser);
/// <summary>
/// Gets paginated jobs with optional filters and sorting
/// </summary>
@@ -91,6 +109,12 @@ public interface IJobRepository
/// </summary>
/// <returns>Summary containing counts by status, job type, and their combinations</returns>
Task<JobSummary> GetSummaryAsync();
/// <summary>
/// Deletes a job by its ID
/// </summary>
/// <param name="jobId">The job ID to delete</param>
Task DeleteAsync(Guid jobId);
}
/// <summary>

View File

@@ -28,7 +28,7 @@ public interface IGeneticService
/// <param name="maxTakeProfit">The maximum take profit percentage</param>
/// <param name="eligibleIndicators">The list of eligible indicators</param>
/// <returns>The created genetic request</returns>
GeneticRequest CreateGeneticRequest(
Task<GeneticRequest> CreateGeneticRequestAsync(
User user,
Ticker ticker,
Timeframe timeframe,