private void RescheduleTask()
        {
            SchedulingManager schedulingManager = SchedulingManager.GetManager();

            ReportsImportScheduledTask newTask = new ReportsImportScheduledTask()
            {
                Key              = this.Key,
                ExecuteTime      = DateTime.UtcNow.AddSeconds(30 * 60),
                LastExecutedTime = this.LastExecutedTime
            };

            schedulingManager.AddTask(newTask);
            SchedulingManager.RescheduleNextRun();
            schedulingManager.SaveChanges();
        }
Exemple #2
0
        public static void Schedule(bool runImmediately = false)
        {
            SchedulingManager manager = SchedulingManager.GetManager();

            var task = ReportsImportTaskHelper.GetTask();

            if (task == null)
            {
                ReportsImportScheduledTask newTask = new ReportsImportScheduledTask()
                {
                    Key = taskKey
                };

                if (runImmediately)
                {
                    newTask.ExecuteTime = DateTime.UtcNow.AddSeconds(-10);
                }
                else
                {
                    newTask.ExecuteTime = DateTime.UtcNow.AddSeconds(30 * 60);
                }

                manager.AddTask(newTask);
                manager.SaveChanges();
            }
            else
            {
                if (runImmediately)
                {
                    if (!task.IsRunning || task.Status == TaskStatus.Failed)
                    {
                        manager.DeleteTaskData(task);

                        ReportsImportScheduledTask newTask = new ReportsImportScheduledTask()
                        {
                            Key              = taskKey,
                            ExecuteTime      = DateTime.UtcNow.AddSeconds(-10),
                            LastExecutedTime = DateTime.UtcNow
                        };

                        manager.AddTask(newTask);
                        manager.SaveChanges();
                    }
                }
            }
        }