using AutomationBLL.Run; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace AutomationSL.EndPoints.Run; // Pull-based agent contract — on-prem/cloud agents long-poll this endpoint (outbound HTTPS only, // no inbound firewall rule needed) instead of anything being pushed to them. public class GetNextJob : BaseEndpoint> { private readonly IRunBLL _bll; public GetNextJob(IRunBLL bll) => _bll = bll; public override void Configure() { Get("/Automation/GetNextJob"); AllowAnonymous(); } public record Parameters( [property: FromHeader] string Login, [property: FromQuery] int AgentId, [property: FromQuery] string SupportedRuntimes, [property: FromQuery] int? WaitSeconds); protected override string? GetCacheKey(Parameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync( Parameters req, LoginDTO loginDTO, CancellationToken ct) { var waitSeconds = req.WaitSeconds is > 0 and <= 30 ? req.WaitSeconds.Value : 30; var result = await _bll.GetNextJob(req.SupportedRuntimes, req.AgentId, waitSeconds, loginDTO, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( result!, CacheKeyLevel.NOT_REQUIRED, loginDTO); } }