public void TasksForAllVersionsOfContenItemShouldBeReturned() { var hello1 = _contentManager.New("hello"); _contentManager.Create(hello1); var hello2 = _contentManager.GetDraftRequired(hello1.Id); Assert.That(hello1.Version, Is.EqualTo(1)); Assert.That(hello2.Version, Is.EqualTo(2)); _scheduledTaskManager.CreateTask("First", _clock.UtcNow.AddHours(1), hello1); _scheduledTaskManager.CreateTask("Second", _clock.UtcNow.AddHours(2), hello2); _scheduledTaskManager.CreateTask("Third", _clock.UtcNow.AddHours(3), null); _session.Flush(); _session.Clear(); var hello = _contentManager.Get(hello1.Id); var tasks = _scheduledTaskManager.GetTasks(hello); Assert.That(tasks.Count(), Is.EqualTo(2)); var firstTask = tasks.Single(x => x.TaskType == "First"); Assert.That(firstTask.ContentItem.Version, Is.EqualTo(1)); var secondTask = tasks.Single(x => x.TaskType == "Second"); Assert.That(secondTask.ContentItem.Version, Is.EqualTo(2)); }
public static void CreateTaskIfNew(this IScheduledTaskManager taskManager, string taskType, DateTime scheduledUtc, ContentItem contentItem) { var outdatedTaskCount = taskManager.GetTasks(taskType, DateTime.UtcNow).Count(); var taskCount = taskManager.GetTasks(taskType).Count(); if (taskCount != 0 && taskCount - outdatedTaskCount > 0) { return; } taskManager.CreateTask(taskType, scheduledUtc, contentItem); }
public IScheduledTask GetPublishTask(ContentItem item) { return(_scheduledTaskManager .GetTasks(item) .Where(task => task.TaskType == PublishTaskType) .SingleOrDefault()); }
DateTime?IArchiveLaterService.GetScheduledArchiveUtc(ArchiveLaterPart archiveLaterPart) { var task = _scheduledTaskManager.GetTasks(archiveLaterPart.ContentItem) .SingleOrDefault(t => t.TaskType == UnpublishTaskType); return(task == null ? null : task.ScheduledUtc); }
public static void EmailAsync(this IScheduledTaskManager _taskManager, ContentItem contentItem) { var tasks = _taskManager.GetTasks(Services.EmailScheduledTaskHandler.TASK_TYPE_EMAIL); if (tasks == null || tasks.Count() < 100) { _taskManager.CreateTask(Services.EmailScheduledTaskHandler.TASK_TYPE_EMAIL, DateTime.UtcNow, contentItem); } }
// This helper method creates the task for us but only if is not already in the system. You should be aware that the task type is not a // unique key: multiple tasks with the same type can exist. Thus if there's an uncompleted task in the system already (because e.g. Orchard // was torn down before it could run) simply creating the task would create a new one. This in turn would have the effect that our Process() // method would run for both tasks, resulting in more frequent execution than what we want. private void CreateTaskIfNew(bool calledFromTaskProcess) { var outdatedTaskCount = _taskManager.GetTasks(TaskType, _clock.UtcNow).Count(); var taskCount = _taskManager.GetTasks(TaskType).Count(); // calledFromTaskProcess is necessary as when this is called from Proces() the current task will still be in the DB, thus there // will be at least a single task there. if ((!calledFromTaskProcess || taskCount != 1) && taskCount != 0 && taskCount - outdatedTaskCount >= 0) { return; // If outdated tasks exists, don't create a new one. } // This task wil run in three minutes. // The third parameter could be a content item that represents the context for the task, but we don't need it now. _taskManager.CreateTask(TaskType, _clock.UtcNow.AddMinutes(3), null); // BTW this helper method and many more libraries aiding Orchard development are contained in the Helpful Libraries module: // http://helpfullibraries.codeplex.com/ }
public static void AppendModelAsync(this IScheduledTaskManager _taskManager, ContentItem contentItem) { var tasks = _taskManager.GetTasks(Services.AppendModelScheduledTaskHandler.TASK_TYPE_APPEND_MODEL); if (tasks == null || tasks.Count() < 100) { _taskManager.CreateTask(Services.AppendModelScheduledTaskHandler.TASK_TYPE_APPEND_MODEL, DateTime.UtcNow, contentItem); } }
public ActionResult Synchronize() { if (_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner)) { // schedula il task per la sincronizzazione var scheduledSynchronizations = _taskManager.GetTasks(Handlers.SynchronizeContactTaskHandler.TaskType); if (scheduledSynchronizations.Count() == 0) { _taskManager.CreateTask(Handlers.SynchronizeContactTaskHandler.TaskType, DateTime.UtcNow.AddSeconds(5), null); _notifier.Add(NotifyType.Information, T("Synchronization started. Please come back on this page in a few minutes to check the result.")); } else { _notifier.Add(NotifyType.Information, T("Synchronization already scheduled at {0:dd-MM-yyyy HH:mm}. Please come back later on this page to check the result.", DateTime.SpecifyKind(scheduledSynchronizations.Min(x => x.ScheduledUtc).Value, DateTimeKind.Utc).ToLocalTime())); } } return(RedirectToAction("Index", "ContactsAdmin")); }
public void CreateTask(ContentItem item) { var name = TransformalizeTaskHandler.GetName(item.As <TitlePart>().Title); var tasks = _manager.GetTasks(name); if (tasks != null && tasks.Any()) { return; } _manager.CreateTask(name, DateTime.UtcNow.AddSeconds(30), item); }
public void UpdateSchedule(string typeName, GDPRPartTypeSchedulingSettings settings) { // compute the name of the scheduled task for this type var taskName = string.Format(Constants.ScheduledTaskFormat, typeName); // check whether this type has a scheduled task var hasTask = _taskManager.GetTasks(taskName).Any(); // if the settings say that the type should be processed, schedule a task if (settings.ScheduleAnonymization || settings.ScheduleErasure) { if (!hasTask) { // create the task _taskManager.CreateTask(taskName, _clock.UtcNow, null); } else { // We run the risk of never processing some ContentItem in some conditions related to // changes that happened to the configuration. var oldSettings = SettingsFromType(typeName); // Conditions describing the fact that the configuration has changed: // - I should anonymize, but this was not the case before var taskChanged = settings.ScheduleAnonymization && !oldSettings.ScheduleAnonymization; // - I should erase, but this was not the case before taskChanged |= settings.ScheduleErasure && !oldSettings.ScheduleErasure; // - I should anonymize, as was the case before, but the time frame now is smaller taskChanged |= (settings.ScheduleAnonymization && oldSettings.ScheduleAnonymization) && settings.AnonymizationDaysToWait < oldSettings.AnonymizationDaysToWait; // - I should erase, as was the case before, but the time frame now is smaller taskChanged |= (settings.ScheduleErasure && oldSettings.ScheduleErasure) && settings.ErasureDaysToWait < oldSettings.ErasureDaysToWait; // - I should anonymize, as was the case before, but the event to check for anonymization has changed taskChanged |= (settings.ScheduleAnonymization && oldSettings.ScheduleAnonymization) && settings.EventForAnonymization != oldSettings.EventForAnonymization; // - I should erase, as was the case before, but event to check for erasure has changed taskChanged |= (settings.ScheduleErasure && oldSettings.ScheduleErasure) && settings.EventForErasure != oldSettings.EventForErasure; // If the configuration has changed, recreate the task if (taskChanged) { _taskManager.DeleteTasks(null, st => st.TaskType == taskName); _taskManager.CreateTask(taskName, _clock.UtcNow, null); } #if DEBUG else { // we are debugging, so we recreate the task, passing a ContentItem to simulate the n-th execution _taskManager.DeleteTasks(null, st => st.TaskType == taskName); _taskManager.CreateTask(taskName, _clock.UtcNow, _siteService.GetSiteSettings().ContentItem); } #endif } } else { // this type is set to have no processing done if (hasTask) { // destroy the task _taskManager.DeleteTasks(null, st => st.TaskType == taskName); } } }