Files
2026-03-24 15:26:03 -05:00

164 lines
4.2 KiB
C#

using LCU.Api.Internal.Dispatcher.HostedServices;
using LCU.Library.Internal.ApiSecurity.Attributes;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace LCU.Api.Internal.Dispatcher.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class HostedServicesController : ControllerBase
{
private readonly ICleanUpJobsHostedService _cleanUpJobsHostedServiceStarter;
private readonly IBatchErroredJobsHostedService _batchErroredJobsServiceStarter;
private readonly IJobSchedulerHostedService _jobSchedulerHostedServiceStarter;
public HostedServicesController(ICleanUpJobsHostedService cleanUpJobsHostedService,
IBatchErroredJobsHostedService batchErroredJobsServiceStarter,
IJobSchedulerHostedService jobSchedulerHostedServiceStarter)
{
_cleanUpJobsHostedServiceStarter = cleanUpJobsHostedService;
_batchErroredJobsServiceStarter = batchErroredJobsServiceStarter;
_jobSchedulerHostedServiceStarter = jobSchedulerHostedServiceStarter;
}
[ApiKey]
[HttpPost("StartCleanUpJobs", Name = "StartCleanUpJobs")]
[ProducesResponseType(200)]
[ProducesResponseType(500)]
public async Task<IActionResult> StartCleanUpJobs()
{
try
{
await _cleanUpJobsHostedServiceStarter.StartAsync();
return Ok();
}
catch (ServiceException)
{
return StatusCode(StatusCodes.Status500InternalServerError);
}
catch (Exception exception)
{
Log.Error(exception, "Unexpected Exception");
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
[ApiKey]
[HttpPost("StopCleanUpJobs", Name = "StopCleanUpJobs")]
[ProducesResponseType(200)]
[ProducesResponseType(500)]
public async Task<IActionResult> StopCleanUpJobs()
{
try
{
await _cleanUpJobsHostedServiceStarter.StopAsync();
return Ok();
}
catch (ServiceException)
{
return StatusCode(StatusCodes.Status500InternalServerError);
}
catch (Exception exception)
{
Log.Error(exception, "Unexpected Exception");
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
[ApiKey]
[HttpPost("StartBatchErroredJobs", Name = "StartBatchErroredJobs")]
[ProducesResponseType(200)]
[ProducesResponseType(500)]
public async Task<IActionResult> StartBatchErroredJobs()
{
try
{
await _batchErroredJobsServiceStarter.StartAsync();
return Ok();
}
catch (ServiceException)
{
return StatusCode(StatusCodes.Status500InternalServerError);
}
catch (Exception exception)
{
Log.Error(exception, "Unexpected Exception");
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
[ApiKey]
[HttpPost("StopBatchErroredJobs", Name = "StopBatchErroredJobs")]
[ProducesResponseType(200)]
[ProducesResponseType(500)]
public async Task<IActionResult> StopBatchErroredJobs()
{
try
{
await _batchErroredJobsServiceStarter.StopAsync();
return Ok();
}
catch (ServiceException)
{
return StatusCode(StatusCodes.Status500InternalServerError);
}
catch (Exception exception)
{
Log.Error(exception, "Unexpected Exception");
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
[ApiKey]
[HttpPost("StartJobScheduler", Name = "StartJobScheduler")]
[ProducesResponseType(200)]
[ProducesResponseType(500)]
public async Task<IActionResult> StartJobScheduler()
{
try
{
await _jobSchedulerHostedServiceStarter.StartAsync();
return Ok();
}
catch (ServiceException)
{
return StatusCode(StatusCodes.Status500InternalServerError);
}
catch (Exception exception)
{
Log.Error(exception, "Unexpected Exception");
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
[ApiKey]
[HttpPost("StopJobScheduler", Name = "StopJobScheduler")]
[ProducesResponseType(200)]
[ProducesResponseType(500)]
public async Task<IActionResult> StopJobScheduler()
{
try
{
await _jobSchedulerHostedServiceStarter.StopAsync();
return Ok();
}
catch (ServiceException)
{
return StatusCode(StatusCodes.Status500InternalServerError);
}
catch (Exception exception)
{
Log.Error(exception, "Unexpected Exception");
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
}
}