| | | 1 | | using Hangfire; |
| | | 2 | | using Hangfire.Storage; |
| | | 3 | | using Hangfire.Storage.Monitoring; |
| | | 4 | | using Microsoft.AspNetCore.Mvc; |
| | | 5 | | using System.Collections.Generic; |
| | | 6 | | using System.Linq; |
| | | 7 | | |
| | | 8 | | // Controllers/HangfireQueueController.cs |
| | | 9 | | using Microsoft.AspNetCore.Authorization; |
| | | 10 | | using OzonOrdersWeb.Areas.Studio2.ViewModels.HangfireQueue; |
| | | 11 | | using Services.HangfireService; |
| | | 12 | | |
| | | 13 | | [Authorize(Roles = "User,Admin")] |
| | | 14 | | [Area("Studio2")] |
| | | 15 | | public class HangfireQueueController : Controller |
| | | 16 | | { |
| | | 17 | | private readonly IHangfireService _hangfireService; |
| | | 18 | | |
| | 0 | 19 | | public HangfireQueueController(IHangfireService hangfireService) |
| | | 20 | | { |
| | 0 | 21 | | _hangfireService = hangfireService; |
| | 0 | 22 | | } |
| | | 23 | | |
| | | 24 | | public IActionResult Index(string queueName = "main", string tab = "enqueued") |
| | | 25 | | { |
| | 0 | 26 | | var queues = _hangfireService.GetAvailableQueues(); |
| | 0 | 27 | | var model = new HangfireJobsViewModel |
| | 0 | 28 | | { |
| | 0 | 29 | | QueueName = queueName, |
| | 0 | 30 | | ActiveTab = tab, |
| | 0 | 31 | | AvailableQueues = queues.ToList(), |
| | 0 | 32 | | |
| | 0 | 33 | | EnqueuedJobs = _hangfireService.GetEnqueuedJobs(queueName), |
| | 0 | 34 | | ProcessingJobs = _hangfireService.GetProcessingJobs(queueName), |
| | 0 | 35 | | SucceededJobs = _hangfireService.GetSucceededJobs(), |
| | 0 | 36 | | DeletedJobs = _hangfireService.GetDeletedJobs() |
| | 0 | 37 | | }; |
| | | 38 | | |
| | 0 | 39 | | return View(model); |
| | | 40 | | } |
| | | 41 | | |
| | | 42 | | [HttpPost] |
| | | 43 | | [ValidateAntiForgeryToken] |
| | | 44 | | public IActionResult DeleteJob([FromBody] DeleteJobRequest request) |
| | | 45 | | { |
| | 0 | 46 | | if (string.IsNullOrEmpty(request.JobId)) |
| | 0 | 47 | | return BadRequest(); |
| | | 48 | | |
| | 0 | 49 | | var success = BackgroundJob.Delete(request.JobId); |
| | | 50 | | |
| | 0 | 51 | | if (success) |
| | 0 | 52 | | return Ok(); |
| | | 53 | | else |
| | 0 | 54 | | return NotFound(); // Задание не найдено или уже завершено |
| | | 55 | | } |
| | | 56 | | } |