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