Pages

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

//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.




18 August, 2013

Sitecore: Scheduler Job in Production server with SwitchMasterToWeb.config

One of our requirement is to schedule Sitecore job in Production environment. Most of the production environments will have SwitchMasterToWeb.config configuration to remove any master database traces in the configuration.

      <agent type="Sitecore.Tasks.DatabaseAgent" method="Run" interval="00:10:00">
        <param desc="database">master</param>
        <param desc="schedule root">/sitecore/system/tasks/schedules</param>
        <LogActivity>true</LogActivity>
      </agent>

We changed this database configuration to “web” but still the job was not executed on the scheduled time.

To investigate further we used the Sitecore admin configuration page /Sitecore/admin/showconfig.aspx. Surprisingly these agent were missing in the output. We analyzed SwitchMasterToWeb configuration and commented the patch configuration to delete these agents. Agent is there in the admin configuration page and job is running on scheduled time.

In SwitchMasterToWeb.config:

      <!--<agent type="Sitecore.Tasks.DatabaseAgent">
         <patch:delete />
      </agent>
      <agent type="Sitecore.Tasks.DatabaseAgent">
         <patch:delete />
      </agent>-->

07 August, 2013

Sitecore: RunAs Different User for Admins

If you are working as a supporting partner for a Sitecore website, you may need to provide access to various content authors. In most of cases, content authors used to say “This item is not accessible”, “my account is having issues with accessing WFFM” etc… To support them and resolve the issue, you may need to request the user whether you can reset their account to check the issue. Once the issue is fixed, you need to ask them change their password.

RunAs module will help the admins to run the Sitecore Backend as like other user i.e. Run the content tree as a different user without their password. Seems to be a security violation!!! There is an option of sending alerts to the configured mail address and also to the defective account user email.

You can download the module here. Download the zip file as it is and install it using Installation Wizard.

Once the module is installed in the Sitecore, you can browse the RunAs page as below.


Following validations/alerts are in place:
  • Requestor should be a Sitecore admin user or should be part of “Sitecore RunAs” role.
  • Requestor account will be validated with their password.
  • Once logged in, a mail will be sent to the configured mail addresses and it can be sent to the impersonated user as well.

Login screen for the Run as different user. I used the same Sitecore login UI.



Requestor      : Admin or a user in “Sitecore RunAs” Role
Password       : Requestor Password
Run As           : User to be impersonated (use domain as well ex: Sitecore\user1)

Configurations: /App_Config/Include/Sitecore.SharedSource.RunAs.config
RunAsFromAddress                – From address used for sending mails
RunAsAdminEmailAddresses   – To addresses for sending mails

Sample Mail:
Run As - Audit Log

8/7/2013 8:01:07 PM

Run As
richard
Requested By
nehemiah
Requested Url
IP Address
1.1.1.1
Machine Name

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