04 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);

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

        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

blockquote { margin: 0; } blockquote p { padding: 15px; background: #eee; border-radius: 5px; } blockquote p::before { content: '\201C'; } blockquote p::after { content: '\201D'; }