Files
Heimdall/src/Heimdall.Application/Services/ICameraAssignmentService.cs
T
Arnaud Dartois 159da2ca26 feat(assign): implement camera-to-agent assignment with failover and strategy support
Multi-agent sites need automatic camera distribution, failover when
an agent goes offline, and rebalancing when new agents join.

Adds CameraAssignment entity with audit trail, 4 assignment strategies
(RoundRobin, GpuPriority, LeastCameras, Failover), a Hangfire failover
job that checks for stale heartbeats every 60s, a discovery coordinator
for leader election, 6 REST endpoints, EF migration, and DI registration.
2026-07-19 12:20:07 +00:00

63 lines
2.3 KiB
C#

using Heimdall.Application.Common;
using Heimdall.Domain.Entities;
namespace Heimdall.Application.Services;
/// <summary>Strategy for assigning cameras to agents.</summary>
public enum AssignmentStrategy
{
/// <summary>Distribute cameras evenly across agents.</summary>
RoundRobin,
/// <summary>Assign detection-heavy cameras to GPU agents first.</summary>
GpuPriority,
/// <summary>Assign to the agent with the fewest cameras.</summary>
LeastCameras,
/// <summary>Reassign cameras from an offline agent to online agents.</summary>
Failover,
}
/// <summary>
/// Manages camera-to-agent assignments across a site.
/// Supports multiple strategies and failover.
/// </summary>
public interface ICameraAssignmentService
{
/// <summary>
/// Assign a single camera to an agent.
/// Releases any existing active assignment for this camera first.
/// </summary>
Task<ServiceResult> AssignCameraAsync(Guid cameraId, Guid agentId, string reason, CancellationToken ct);
/// <summary>
/// Assign all cameras of a site according to the given strategy.
/// Returns the number of cameras assigned.
/// </summary>
Task<ServiceResult<int>> AssignSiteCamerasAsync(Guid siteId, AssignmentStrategy strategy, CancellationToken ct);
/// <summary>
/// Handle agent failover: reassign all cameras from offlineAgent to the best
/// available online agents in the same site.
/// </summary>
Task<ServiceResult<IReadOnlyList<Camera>>> FailoverAgentAsync(Guid offlineAgentId, CancellationToken ct);
/// <summary>
/// Get the currently active assignment for a camera, or null if unassigned.
/// </summary>
Task<CameraAssignment?> GetActiveAssignmentAsync(Guid cameraId, CancellationToken ct);
/// <summary>
/// Get all active assignments for a given agent (its current workload).
/// </summary>
Task<List<CameraAssignment>> GetAgentAssignmentsAsync(Guid agentId, CancellationToken ct);
/// <summary>
/// Get the assignment history for a specific camera.
/// </summary>
Task<List<CameraAssignment>> GetCameraHistoryAsync(Guid cameraId, CancellationToken ct);
/// <summary>
/// Release a camera from its current agent (makes it unassigned).
/// </summary>
Task<ServiceResult> ReleaseCameraAsync(Guid cameraId, CancellationToken ct);
}