Exemplo n.º 1
0
        public static void ScheduleTask(DateTime executeTime)
        {
            SchedulingManager schedulingManager = SchedulingManager.GetManager();

            var existingTask = schedulingManager.GetTaskData().FirstOrDefault(x => x.Key == HashtagSearchScheduledTask.TaskKey);

            if (existingTask == null && usgConfig.RunHashtagSearch && !usgConfig.UserKey.IsNullOrWhitespace())
            {
                // Create a new scheduled task
                HashtagSearchScheduledTask newTask = new HashtagSearchScheduledTask()
                {
                    ExecuteTime = executeTime
                };
                schedulingManager.AddTask(newTask);
            }
            else if (usgConfig.RunHashtagSearch && !usgConfig.UserKey.IsNullOrWhitespace())
            {
                // Updates the existing scheduled task
                existingTask.ExecuteTime = executeTime;
            }
            else
            {
                //Delete the task
                schedulingManager.DeleteItem(existingTask);
            }

            SchedulingManager.RescheduleNextRun();
            schedulingManager.SaveChanges();
        }
Exemplo n.º 2
0
        internal static void AddScheduledTask(ScheduledTask newTask)
        {
            SchedulingManager manager = SchedulingManager.GetManager();

            manager.AddTask(newTask);
            manager.SaveChanges();
        }
Exemplo n.º 3
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();
                    }
                }
            }
        }
        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();
        }
Exemplo n.º 5
0
        public override void ExecuteTask()
        {
            SearchSocial();

            if (usgConfig.RunHashtagSearch && !usgConfig.UserKey.IsNullOrWhitespace())
            {
                SchedulingManager schedulingManager = SchedulingManager.GetManager();

                HashtagSearchScheduledTask newTask = new HashtagSearchScheduledTask()
                {
                    ExecuteTime = DateTime.UtcNow.AddMinutes(usgConfig.SearchFrequency).ToUniversalTime()
                };

                schedulingManager.AddTask(newTask);
                schedulingManager.SaveChanges();
            }
        }
Exemplo n.º 6
0
        private Guid StartOptimizeAlbumItemsTask(Guid albumId)
        {
            SchedulingManager manager = SchedulingManager.GetManager();

            Guid guid = Guid.NewGuid();

            AlbumOptimizationTask albumOptimizationTask = new AlbumOptimizationTask()
            {
                Id      = guid,
                AlbumId = albumId
            };

            manager.AddTask(albumOptimizationTask);

            manager.SaveChanges();

            return(guid);
        }
Exemplo n.º 7
0
        /// <summary>
        /// CreateTask
        /// </summary>
        public static void CreateTask()
        {
            SchedulingManager manager = SchedulingManager.GetManager();
            string            title   = "RenewContentTask";

            var tasks = manager.GetTaskData().Where(i => i.Title == title);

            foreach (var task in tasks)
            {
                manager.DeleteTaskData(task);
            }
            RenewContentTask newTask = new RenewContentTask()
            {
                Title       = title,
                ExecuteTime = DateTime.UtcNow.AddMinutes(1),
            };

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