Add jobs
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
using Managing.Domain.Backtests;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Application.Abstractions.Repositories;
|
||||
|
||||
/// <summary>
|
||||
/// Repository interface for managing backtest jobs in the queue system
|
||||
/// </summary>
|
||||
public interface IBacktestJobRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new backtest job
|
||||
/// </summary>
|
||||
Task<BacktestJob> CreateAsync(BacktestJob job);
|
||||
|
||||
/// <summary>
|
||||
/// Claims the next available job using PostgreSQL advisory locks.
|
||||
/// Returns null if no jobs are available.
|
||||
/// </summary>
|
||||
/// <param name="workerId">The ID of the worker claiming the job</param>
|
||||
/// <param name="jobType">Optional job type filter. If null, claims any job type.</param>
|
||||
Task<BacktestJob?> ClaimNextJobAsync(string workerId, JobType? jobType = null);
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing job
|
||||
/// </summary>
|
||||
Task UpdateAsync(BacktestJob job);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all jobs for a specific bundle request
|
||||
/// </summary>
|
||||
Task<IEnumerable<BacktestJob>> GetByBundleRequestIdAsync(Guid bundleRequestId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all jobs for a specific user
|
||||
/// </summary>
|
||||
Task<IEnumerable<BacktestJob>> GetByUserIdAsync(int userId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a job by its ID
|
||||
/// </summary>
|
||||
Task<BacktestJob?> GetByIdAsync(Guid jobId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets stale jobs (jobs that are Running but haven't sent a heartbeat in the specified timeout)
|
||||
/// </summary>
|
||||
/// <param name="timeoutMinutes">Number of minutes since last heartbeat to consider stale</param>
|
||||
Task<IEnumerable<BacktestJob>> GetStaleJobsAsync(int timeoutMinutes = 5);
|
||||
|
||||
/// <summary>
|
||||
/// Resets stale jobs back to Pending status
|
||||
/// </summary>
|
||||
Task<int> ResetStaleJobsAsync(int timeoutMinutes = 5);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all running jobs assigned to a specific worker
|
||||
/// </summary>
|
||||
Task<IEnumerable<BacktestJob>> GetRunningJobsByWorkerIdAsync(string workerId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all jobs for a specific genetic request ID
|
||||
/// </summary>
|
||||
Task<IEnumerable<BacktestJob>> GetByGeneticRequestIdAsync(string geneticRequestId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets paginated jobs with optional filters and sorting
|
||||
/// </summary>
|
||||
/// <param name="page">Page number (1-based)</param>
|
||||
/// <param name="pageSize">Number of items per page</param>
|
||||
/// <param name="sortBy">Field to sort by</param>
|
||||
/// <param name="sortOrder">Sort order ("asc" or "desc")</param>
|
||||
/// <param name="status">Optional status filter</param>
|
||||
/// <param name="jobType">Optional job type filter</param>
|
||||
/// <param name="userId">Optional user ID filter</param>
|
||||
/// <param name="workerId">Optional worker ID filter</param>
|
||||
/// <param name="bundleRequestId">Optional bundle request ID filter</param>
|
||||
/// <returns>Tuple of jobs and total count</returns>
|
||||
Task<(IEnumerable<BacktestJob> Jobs, int TotalCount)> GetPaginatedAsync(
|
||||
int page,
|
||||
int pageSize,
|
||||
string sortBy = "CreatedAt",
|
||||
string sortOrder = "desc",
|
||||
BacktestJobStatus? status = null,
|
||||
JobType? jobType = null,
|
||||
int? userId = null,
|
||||
string? workerId = null,
|
||||
Guid? bundleRequestId = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets summary statistics of jobs grouped by status and job type
|
||||
/// </summary>
|
||||
/// <returns>Summary containing counts by status, job type, and their combinations</returns>
|
||||
Task<JobSummary> GetSummaryAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Summary statistics for jobs
|
||||
/// </summary>
|
||||
public class JobSummary
|
||||
{
|
||||
public List<JobStatusCount> StatusCounts { get; set; } = new();
|
||||
public List<JobTypeCount> JobTypeCounts { get; set; } = new();
|
||||
public List<JobStatusTypeCount> StatusTypeCounts { get; set; } = new();
|
||||
public int TotalJobs { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Count of jobs by status
|
||||
/// </summary>
|
||||
public class JobStatusCount
|
||||
{
|
||||
public BacktestJobStatus Status { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Count of jobs by job type
|
||||
/// </summary>
|
||||
public class JobTypeCount
|
||||
{
|
||||
public JobType JobType { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Count of jobs by status and job type combination
|
||||
/// </summary>
|
||||
public class JobStatusTypeCount
|
||||
{
|
||||
public BacktestJobStatus Status { get; set; }
|
||||
public JobType JobType { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user