I wanted to build something similar to the following article: Schedule Sitecore Database cleanup tasks programatically
I do know that the cleanup database functionality is in Sitecore's launchpad -> Control Panel in my instance running version 8.1
The author does, what I believe, is a custom setup to call Sitecore's cleanup service. Code from the article is the following:
namespace Sitecore.Foundation.ScheduledTasks.Services
{
using System;
using System.Collections.Generic;
using System.Web;
using log4net;
using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Mvc.Extensions;
using Sitecore.Mvc.Presentation;
using Sitecore.Pipelines;
using Sitecore.Pipelines.RenderField;
using Sitecore.Tasks;
using Sitecore.Web.UI.WebControls;
using Sitecore.ExperienceContentManagement.Administration.Helpers.DbCleanup;
public class ScheduledTasksService
{
public void Execute(Item[] items, CommandItem command, ScheduleItem schedule)
{
this.CleanupBlobs();
}
public void CleanupBlobs()
{
try
{
CleanupTaskRunner runner = new CleanupTaskRunner();
TaskToRun task = new TaskToRun();
task.Database = "web";
task.Task = CleanupTasks.CleanupBlobs;
runner.RunCleanUp(new TaskToRun[] { task });
}
catch(Exception e)
{
Log.Error("Error while cleaning Blobs table", e, this);
}
}
}
}
I wanted to know if there is a more standard way of doing so. I don't have access to the Sitecore.ExperienceContentManagement.Administration.Helpers.DbCleanup
/sitecore/system/tasks
- there will be aCommand
referencingScheduledTasksService
, and there will be aSchedule
item with the schedule. Here is an old post addressing how to handle code that you want to run recurringly: SItecore Scheduling. If the site can run the code that you posted then you can always decompile the dll in question if you want to see that implementation of the Cleanup code.Sitecore.ExperienceContentManagement.Administration.dll
, the author of the post extracted the relevant code from the dll and pasted it in a scheduler. Are you saying your are getting red squiggly lines in Visual Studio when you copy paste his code? You might need to add Sitecore references to your project through NuGet to get the Intellisense to recognize that your custom code can invoke Sitecore's native code.