feat(analysis): scheduler de jobs d'analyse avec routage par capacités, priorités et dead-letter (#159)
This commit is contained in:
1 parent
760aa7baf8
commit
ca43c6d28e
15 files changed
+1696
-1
No files matched your search
@@ -0,0 +1,72 @@
|
||||
using Heimdall.Application.Common;
|
||||
using Heimdall.Domain.Entities;
|
||||
using Heimdall.Domain.Enums;
|
||||
|
||||
namespace Heimdall.Application.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Schedules analysis jobs by selecting the best agent based on capabilities,
|
||||
/// site affinity, and current load. Manages the full lifecycle of analysis jobs.
|
||||
/// </summary>
|
||||
public interface IAnalysisJobSchedulerService
|
||||
{
|
||||
/// <summary>
|
||||
/// Create a new analysis job and enqueue it for scheduling.
|
||||
/// </summary>
|
||||
Task<ServiceResult<AnalysisJob>> CreateJobAsync(
|
||||
Guid cameraId,
|
||||
AnalysisJobType jobType,
|
||||
AnalysisJobPriority priority,
|
||||
string? parametersJson = null,
|
||||
CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Select the best agent for a pending job and dispatch it.
|
||||
/// Selection criteria: capabilities → site affinity → current load.
|
||||
/// Returns null if no suitable agent is available.
|
||||
/// </summary>
|
||||
Task<ServiceResult<AnalysisJob>> DispatchJobAsync(Guid jobId, CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
/// Process the next batch of pending jobs (called by the Hangfire dispatcher).
|
||||
/// Selects agents and dispatches as many jobs as possible.
|
||||
/// </summary>
|
||||
Task<int> ProcessPendingJobsAsync(int maxJobs, CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
/// Mark a job as started by the agent.
|
||||
/// </summary>
|
||||
Task<ServiceResult> StartJobAsync(Guid jobId, CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
/// Mark a job as completed with results.
|
||||
/// </summary>
|
||||
Task<ServiceResult> CompleteJobAsync(Guid jobId, CancellationToken ct, string? resultJson = null);
|
||||
|
||||
/// <summary>
|
||||
/// Report a job failure — triggers retry or dead-lettering.
|
||||
/// </summary>
|
||||
Task<ServiceResult> FailJobAsync(Guid jobId, string errorMessage, CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
/// Cancel a pending or running job.
|
||||
/// </summary>
|
||||
Task<ServiceResult> CancelJobAsync(Guid jobId, CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
/// Get jobs stuck in Dispatched/Running state longer than their timeout.
|
||||
/// Returns them for the dispatcher to clean up.
|
||||
/// </summary>
|
||||
Task<IReadOnlyList<AnalysisJob>> GetTimedOutJobsAsync(CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
/// Get the best agent for a given job based on capabilities, site affinity, and load.
|
||||
/// Used internally and for testing/validation.
|
||||
/// </summary>
|
||||
Task<Agent?> SelectBestAgentAsync(AnalysisJob job, CancellationToken ct);
|
||||
|
||||
/// <summary>
|
||||
/// Get pending jobs ordered by priority (security first).
|
||||
/// </summary>
|
||||
Task<IReadOnlyList<AnalysisJob>> GetPendingJobsAsync(int limit, CancellationToken ct);
|
||||
}
|
||||
Reference in new issue
Block a user