forked from ddrilling/AsbCloudServer
45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using AsbCloudApp.Data;
|
|
using AsbCloudInfrastructure.Background;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[Authorize]
|
|
[ApiController]
|
|
public class PeriodicBackgroundWorkerController : ControllerBase
|
|
{
|
|
private readonly PeriodicBackgroundWorker worker;
|
|
|
|
public PeriodicBackgroundWorkerController(PeriodicBackgroundWorker worker)
|
|
{
|
|
this.worker = worker;
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult GetAll()
|
|
{
|
|
var result = new
|
|
{
|
|
currentWork = (BackgroundWorkDto?)worker.CurrentWork,
|
|
worker.MainLoopLastException,
|
|
works = worker.Works.Select(work => (BackgroundWorkDto)work.Work),
|
|
};
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpPost("restart"), Obsolete("temporary method")]
|
|
public async Task<IActionResult> RestartAsync(CancellationToken token)
|
|
{
|
|
await worker.StopAsync(token);
|
|
await worker.StartAsync(token);
|
|
return Ok();
|
|
}
|
|
}
|
|
}
|