TIHIDI: Sitecore Scheduling with SiteCron 2.1.8 in powerful ways!

I have been using SiteCron for a while now and I get a steady stream of questions about the module. I thought its time I documented how I use SiteCron.

I do have some custom implementations of the IJob interface but I use PowerShell based jobs predominantly.

First go through some of my previous posts about SiteCron. Once SiteCron is installed and you are ready to rock, there is no better place to start than Sitecore PowerShell.

I get most of my work done via PowerShell scripts and this should not be any different.

SiteCron by default comes with a PowerShell Job which you can use.

Here are a few tips which help me:

  • Create a new SiteCron job and update the Type using the sample Execute PowerShell Script job.
  • Remember the Default PowerShell Job included out of the box only uses the first item in the Items field. This is to make sure that there is no recurrence, which means that you can only run one PowerShell script item at once. If you have a different need, utilize the code in the default PowerShell Job.
  • All of my jobs are automated and run at odd times. Make sure your Sitecore Instance running the jobs is up and running. I usually do this by running a Windows scheduler to call the instance url based on the needs.
  • Add the context db in your scripts.
    <# Set DB Context as Master #>
    Set-Location master:
  • Non-console based output might cause issues so use SilentlyContinue.
    $ProgressPreference = ‘SilentlyContinue’
  • Run in admin context when you can.
    $admin = [Sitecore.Security.Accounts.User]::FromName(“sitecore\admin”, $false)
    [Sitecore.Security.Accounts.UserSwitcher]::Enter($admin)
  • Use the zSiteCronItemID which gets passed in by SiteCron and write the LastRunLog in the Scheduled Item Job.
    • $script:logEntries = “”
    • function WriteToLog($message)
      {
      Write-Log $message
      $script:logEntries += $(Get-Date –f o) + ” ” + $message + “`n”
      }
    • finally {
      if($zSiteCronItemID) {
      $scheduleItem = Get-Item master: -ID $zSiteCronItemID
      if($scheduleItem)
      {
      $scheduleItem.Editing.BeginEdit()
      $scheduleItem[“LastRunLog”]=$script:logEntries
      $scheduleItem=$scheduleItem.Editing.EndEdit()
      }
      }

 

TIHIDI: Stands for This Is How I Do It. I am going to write a series of blog posts going through how I do Sitecore related work. Hope it helps you!

If you have any questions or concerns, please get in touch with me. (@akshaysura13 on twitter or on Slack).

Leave a Reply

Your email address will not be published. Required fields are marked *