Developer forum

Forum » Development » Repository task executed every 5. minute

Repository task executed every 5. minute

Anders Ebdrup
Anders Ebdrup
Reply

Dear Dynamicweb,

We experience that repository task set to run only once are runned every time as there is no check on whether the property RepeatInMinutes is greater than 0 - Please find the code below.

 

        public static void RunTasks()
        {
            var now = DateTime.Now;
            var taskService = ServiceLocator.Current.GetInstance<ITaskService>();
            var repositoryService = ServiceLocator.Current.GetInstance<IRepositoryService>();
            foreach (var repositoryName in repositoryService.GetRepositories())
            {
                foreach (var taskItem in repositoryService.GetRepositoryItems(repositoryName).Where(ri => ri.TypeName.Equals("Task")))
                {
                    try
                    {
                        var task = taskService.LoadTask(repositoryName, taskItem.Name);
 
                        var shouldRunTask = task.Start.CompareTo(DateTime.Now) <= 0 && task.End.CompareTo(DateTime.Now) >= 0 &&
                                            !task.IsTaskRunning &&                                             
                                             (task.LastExecutionStartTime is null || now.Subtract(task.LastExecutionStartTime.Value).TotalMinutes > task.RepeatInMinutes ||
                                            !(task.LastExecutionSuccessful ?? false));
 
                        if (!shouldRunTask)
                            continue;
 
                        task.Run();
                    }
                    catch (Exception ex)
                    {
                        using (var tracker = Tracker.GetTracker("TaskRunner"))
                        {
                            tracker.LogException(ex.Message, ex);
                        }
                    }
                }
            }
        }

 

Hope you can try to look into this?

 

Best regards, Anders

 

Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Anders,
that is a bug and will be fixed today/tomorrow.
BR, Dmitrij

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Devops#13710

 

You must be logged in to post in the forum