public ActionResult Sweep()
        {
            if (!_taskScheduler.VerifyAuthToken(Request.Headers["X-AUTH-TOKEN"]))
            {
                return(new HttpUnauthorizedResult());
            }

            var pendingTasks  = _scheduledTaskService.GetPendingTasks();
            var prevTaskStart = DateTime.UtcNow;
            var count         = 0;

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

                if (i > 0)
                {
                    // 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.
                    _services.DbContext.ReloadEntity(task);
                }

                if (task.IsPending)
                {
                    prevTaskStart = DateTime.UtcNow;
                    _taskExecutor.Execute(task);
                    count++;
                }
            }

            return(Content("{0} of {1} pending tasks executed".FormatInvariant(count, pendingTasks.Count)));
        }
Пример #2
0
        public ActionResult Sweep()
        {
            if (!_taskScheduler.VerifyAuthToken(Request.Headers["X-AUTH-TOKEN"]))
            {
                return(new HttpUnauthorizedResult());
            }

            var pendingTasks  = _scheduledTaskService.GetPendingTasks();
            var prevTaskStart = DateTime.UtcNow;
            var count         = 0;

            foreach (var task in pendingTasks)
            {
                var elapsedSincePrevTask = DateTime.UtcNow - prevTaskStart;
                if (elapsedSincePrevTask >= TimeSpan.FromMinutes(_taskScheduler.SweepIntervalMinutes))
                {
                    // the previous Task execution in this loop took longer
                    // than the scheduler's sweep interval. Most likely a subsequent
                    // Sweep call executed it already in another HTTP request.
                    // 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.
                    _services.DbContext.ReloadEntity(task);
                }

                if (task.IsPending)
                {
                    prevTaskStart = DateTime.UtcNow;
                    _taskExecutor.Execute(task);
                    count++;
                }
            }

            return(Content("{0} tasks executed".FormatInvariant(count)));
        }
Пример #3
0
        public ActionResult Sweep()
        {
            if (!_taskScheduler.VerifyAuthToken(Request.Headers["X-AUTH-TOKEN"]))
            {
                return(new HttpUnauthorizedResult());
            }

            var pendingTasks   = _scheduleTaskService.GetPendingTasks();
            var count          = 0;
            var taskParameters = QueryString.Current.ToDictionary();

            if (pendingTasks.Count > 0)
            {
                Virtualize(taskParameters);
            }

            for (var i = 0; i < pendingTasks.Count; 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.
                    _services.DbContext.ReloadEntity(task);
                    task.LastHistoryEntry = _scheduleTaskService.GetLastHistoryEntryByTaskId(task.Id);
                }

                if (task.IsPending)
                {
                    _taskExecutor.Execute(task, taskParameters);
                    count++;
                }
            }

            return(Content("{0} of {1} pending tasks executed".FormatInvariant(count, pendingTasks.Count)));
        }