Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id)
        {
            var(profile, provider) = await LoadProfileAndProvider(id);

            if (profile == null)
            {
                return(RedirectToAction("List"));
            }

            var model             = new ExportProfileModel();
            var lastExecutionInfo = await _taskStore.GetLastExecutionInfoByTaskIdAsync(profile.TaskId);

            await PrepareProfileModel(model, profile, provider, lastExecutionInfo, true);

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetTaskRunInfo(int id /* taskId */)
        {
            // We better not check permission here.
            var lastExecutionInfo = await _taskStore.GetLastExecutionInfoByTaskIdAsync(id);

            var task = lastExecutionInfo?.Task ?? await _taskStore.GetTaskByIdAsync(id);

            if (task == null)
            {
                return(NotFound());
            }

            var model = await task.MapAsync(lastExecutionInfo);

            var lastRunHtml = await this.InvokeViewAsync("_LastRun", model);

            var nextRunHtml = await this.InvokeViewAsync("_NextRun", model);

            return(Json(new { lastRunHtml, nextRunHtml }));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(int id)
        {
            var profile = await _db.ImportProfiles
                          .Include(x => x.Task)
                          .FindByIdAsync(id, false);

            if (profile == null)
            {
                return(NotFound());
            }

            var model             = new ImportProfileModel();
            var lastExecutionInfo = await _taskStore.GetLastExecutionInfoByTaskIdAsync(profile.TaskId, true);

            await PrepareProfileModel(model, profile, lastExecutionInfo, true);

            return(View(model));
        }
        private async Task Poll(HttpContext context, ITaskStore taskStore, ITaskExecutor executor, IDictionary <string, string> taskParameters)
        {
            var pendingTasks = await taskStore.GetPendingTasksAsync();

            var numTasks    = pendingTasks.Count;
            var numExecuted = 0;

            if (pendingTasks.Any())
            {
                await Virtualize(context, taskParameters);
            }

            for (var i = 0; i < numTasks; i++)
            {
                var task = pendingTasks[i];

                if (i > 0 /*&& (DateTime.UtcNow - _sweepStart).TotalMinutes > _taskScheduler.SweepIntervalMinutes*/)
                {
                    // Maybe a subsequent Sweep call or another machine in a webfarm executed
                    // successive tasks already.
                    // To be able to determine this, we need to reload the entity from the database.
                    // The TaskExecutor will exit when the task should be in running state then.
                    await taskStore.ReloadTaskAsync(task);

                    task.LastExecution = await taskStore.GetLastExecutionInfoByTaskIdAsync(task.Id);
                }

                if (task.IsPending)
                {
                    await executor.ExecuteAsync(task, context, taskParameters);

                    numExecuted++;
                }
            }

            context.Response.StatusCode = StatusCodes.Status200OK;
            await context.Response.WriteAsync($"{numExecuted} of {numTasks} pending tasks executed.");
        }
        public async Task <IViewComponentResult> InvokeAsync(int taskId, string returnUrl, bool cancellable = true, bool reloadPage = false)
        {
            var lastExecutionInfo = await _taskStore.GetLastExecutionInfoByTaskIdAsync(taskId);

            var task = lastExecutionInfo?.Task ?? await _taskStore.GetTaskByIdAsync(taskId);

            if (task == null)
            {
                return(Empty());
            }

            var model = await task.MapAsync(lastExecutionInfo);

            ViewBag.CanRead = await _permissionService.AuthorizeAsync(Permissions.System.ScheduleTask.Read);

            ViewBag.CanExecute = await _permissionService.AuthorizeAsync(Permissions.System.ScheduleTask.Execute);

            ViewBag.ReturnUrl   = returnUrl;
            ViewBag.Cancellable = cancellable;
            ViewBag.ReloadPage  = reloadPage;

            return(View(model));
        }