Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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>();
                };
            });
        }
Esempio n. 3
0
 public static async Task <ServicesResponse <BackendTask> > GetTaskState(Adapter adapter, BackendTask task)
 {
     return(await ApiService.GetRequestAsync <BackendTask>(adapter, $"task/{task.BackendTaskId}"));
 }
Esempio n. 4
0
 public Task <ApiResponse <bool> > HideBackendTask(BackendTask backendTask)
 {
     throw new NotImplementedException();
 }