public virtual async Task <IActionResult> RunNow(int id) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageScheduleTasks)) { return(AccessDeniedView()); } try { //try to get a schedule task with the specified id var scheduleTask = await _scheduleTaskService.GetTaskByIdAsync(id) ?? throw new ArgumentException("Schedule task cannot be loaded", nameof(id)); //ensure that the task is enabled var task = new Task(scheduleTask) { Enabled = true }; await task.ExecuteAsync(true, false); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.System.ScheduleTasks.RunNow.Done")); } catch (Exception exc) { await _notificationService.ErrorNotificationAsync(exc); } return(RedirectToAction("List")); }
public virtual async Task <IActionResult> RunTask(string taskType) { var scheduleTask = await _scheduleTaskService.GetTaskByTypeAsync(taskType); if (scheduleTask == null) { //schedule task cannot be loaded return(NoContent()); } var task = new Task(scheduleTask); await task.ExecuteAsync(); return(NoContent()); }