diff --git a/AsbCloudWebApi/Controllers/PeriodicBackgroundWorkerController.cs b/AsbCloudWebApi/Controllers/PeriodicBackgroundWorkerController.cs
index d7f666a0..0a493456 100644
--- a/AsbCloudWebApi/Controllers/PeriodicBackgroundWorkerController.cs
+++ b/AsbCloudWebApi/Controllers/PeriodicBackgroundWorkerController.cs
@@ -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);
}
+ ///
+ /// Запуск задачи по Id
+ ///
+ /// Id задачи
+ ///
+ ///
+ [HttpGet("start/{workId}")]
+ public async Task 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 RestartAsync(CancellationToken token)
{