0

I have used Sitecore scheduler to schedule a Powershell task. The task rebuilds the Link databases of Master and Core.

As the tasks are long-running, I am running them as Async. So in the logs, we have just 2 entries, almost simultaneously.

Is there any way we can identify if the rebuild is complete successfully in the backend?

Edit1: Code used:

$database = Get-Database -Name "core"
[Sitecore.Globals]::LinkDatabase.Rebuild($database)
$database = Get-Database -Name "master"
[Sitecore.Globals]::LinkDatabase.Rebuild($database)
3
  • Are you using [Sitecore.Globals]::LinkDatabase.Rebuild($database) command to rebuild your database? Can you add some code snippets? Jul 26 at 14:55
  • @SumitBhatia: Yes I am using the same. Jul 27 at 6:07
  • Did you try adding some logs in your Powershell script, that can write once the Rebuild database finished? Jul 27 at 7:52

1 Answer 1

0

You can update your code in PowerShell something like this that will write a log for you once the Rebuild Link Databases task will be finished for all the databases. Her is the code snippets.

foreach($database in Get-Database) {
    if(!$database.ReadOnly) {
        
        Write-Log "Rebuilding the $($database) link database."
        
        $time = Measure-Command {
            [Sitecore.Globals]::LinkDatabase.Rebuild($database)
        }
        
        Write-Log "Completed rebuilding the $($database) link database in $($time.TotalSeconds) seconds."
    }
}

It will create a log file in your App_Data folder.

enter image description here

And the logs will be written something like this.

ManagedPoolThread #17 13:42:12 INFO  Rebuilding the master link database.
ManagedPoolThread #17 13:42:49 INFO  Completed rebuilding the master link database in 37.7867178 seconds.
ManagedPoolThread #17 13:42:49 INFO  Rebuilding the web link database.
ManagedPoolThread #17 13:43:28 INFO  Completed rebuilding the web link database in 38.3885773 seconds.
ManagedPoolThread #17 13:43:28 INFO  Rebuilding the core link database.
ManagedPoolThread #17 13:44:26 INFO  Completed rebuilding the core link database in 58.6195402 seconds.

I think this way you can make sure that your Rebuild Link Databases task has been successfully completed.

Hope this will help.

6
  • I tried to have the custom logging. From the jobs page, I can see the task running. Somehow the log is not showing us either in the log files or Application insight. Jul 28 at 8:00
  • Okay, so what happens when you try running your PowerShell script manually? Without any scheduler? @NutsAndBolts Jul 28 at 8:17
  • No logs in Application Insight. but found the log in SPE.log.20220727.txt Jul 28 at 9:06
  • Yes as per my answer the logs will be generated in the SPE.log. As Sitecore will generate all the logs into this file. So you can check with this log. Do you want to write log in any other log file? @NutsAndBolts Jul 28 at 10:17
  • I was expecting entry to this file even when the script was triggered by the scheduler, as I am running it through the scheduler and mentioned in the question. It would have been great if we could have it in the Application Insight. Jul 28 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.