Friday, 4 October 2013

Sitecore: Ideal way to execute a long running job

One of our requirement was to execute a long running job in Sitecore Content Tree. In many cases, we end up in Timed out error. Obviously we can increase request timed out configuration. But Sitecore has a very good way of executing such long running task in a ProgressBox.

ProgressBox.Execute(JobName, JobTitle, ProgressBoxMethod, Params);

//Sitecore.Shell.Applications.Dialogs.ProgressBoxes
ProgressBox.Execute("Job Name", "Job Title ", new ProgressBoxMethod(ExecuteOperation), item);

This line of code will start progress box and the functionality will be executed in the
ProgressBoxMethod.

        protected void ExecuteOperation(params object[] parameters)
        {
            //Do the operations
           
            //Logging for the job
            Sitecore.Context.Job.Status.Messages.Add("Logs for the job: JobName");
           
            //Is the job done?
            if (Sitecore.Context.Job.IsDone)
            {
                //On completing the job
            }           
        }

By using the progress box, the long running tasks are executed successfully without getting any timed out errors. This has other methods to handle the queuing asynchronously.




No comments:

Post a Comment

Articles

Automatically create new version for Lock & Edit without workflow

Sitecore will create a new version on Lock and Edit if the item is tied to a workflow. For our case, version has to be created even withou...