public async Task <IActionResult> HideBackendTask(BackendTask backendTask) { if (backendTask?.Id == null && backendTask?.UserId == User.Identity.Name) { return(BadRequest()); } backendTask.IsVisible = false; _context.Entry(backendTask).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BackendTaskExists(backendTask.Id)) { return(NotFound()); } else { throw; } } return(Ok(true)); }
private void TrackBackendTask(Adapter adapter, BackendTask task) { _logger.LogInformation("Sending VM request to backend"); _taskQueue.QueueBackgroundWorkItem(async token => { using (var scope = _serviceScopeFactory.CreateScope()) { var scopedServices = scope.ServiceProvider; var context = scopedServices.GetRequiredService <EasyAdminContext>(); while (task.State != "success" && task.State != "error") { var checkTaskStateResponse = await EasyAdmin.Services.VMware.TaskService.GetTaskState(adapter, task); if (checkTaskStateResponse.isSuccess) { var newTaskState = checkTaskStateResponse.resultObject; task.State = newTaskState.State; task.Result = newTaskState.Result; task.Status = "Виртуальная машина успешно создана"; } else { task.State = "error"; task.Result = task.Status = "Ошибка обновления статуса запроса"; } System.Threading.Thread.Sleep(5000); } context.Entry(task).State = EntityState.Modified; await context.SaveChangesAsync(); _logger.LogInformation("Vm created successfully"); //var mailer = scopedServices.GetRequiredService<IMailerService>(); }; }); }
public static async Task <ServicesResponse <BackendTask> > GetTaskState(Adapter adapter, BackendTask task) { return(await ApiService.GetRequestAsync <BackendTask>(adapter, $"task/{task.BackendTaskId}")); }
public Task <ApiResponse <bool> > HideBackendTask(BackendTask backendTask) { throw new NotImplementedException(); }