forked from ddrilling/AsbCloudServer
Merge branch 'dev' into feature/#34164218-process-map-plan-drilling-rotor-and-slide
This commit is contained in:
commit
1c095b4906
@ -2,6 +2,7 @@
|
||||
using AsbCloudInfrastructure.Background;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@ -15,10 +16,14 @@ namespace AsbCloudWebApi.Controllers
|
||||
public class PeriodicBackgroundWorkerController : ControllerBase
|
||||
{
|
||||
private readonly PeriodicBackgroundWorker worker;
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
|
||||
public PeriodicBackgroundWorkerController(PeriodicBackgroundWorker worker)
|
||||
public PeriodicBackgroundWorkerController(
|
||||
PeriodicBackgroundWorker worker,
|
||||
IServiceProvider serviceProvider)
|
||||
{
|
||||
this.worker = worker;
|
||||
this.serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -33,6 +38,27 @@ namespace AsbCloudWebApi.Controllers
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Запуск задачи по Id
|
||||
/// </summary>
|
||||
/// <param name="workId">Id задачи</param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("start/{workId}")]
|
||||
public async Task<IActionResult> Start(string workId, CancellationToken token)
|
||||
{
|
||||
var targetWork = worker.Works.FirstOrDefault(w => w.Work.Id == workId);
|
||||
if(targetWork is not null)
|
||||
{
|
||||
using (var scope = serviceProvider.CreateScope()) {
|
||||
|
||||
var result = await targetWork.Work.Start(scope.ServiceProvider, token);
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
return BadRequest("Work not found by workId");
|
||||
}
|
||||
|
||||
[HttpPost("restart"), Obsolete("temporary method")]
|
||||
public async Task<IActionResult> RestartAsync(CancellationToken token)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user