Developer forum

Forum » CMS - Standard features » Notification for failed index run

Notification for failed index run

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

We have a site where rebuilding the index (the new one) fails from time to time. We haven't figured out why yet and are first trying to figure out when it happens and how often. Currenty we are parsing the log files to send out a notification, but I was wondering if there's a better way to do this. Is there a subscriber that fires upon index completion that we could tap into? And if not, would it make sense to add one? Or maybe have a UI to configure an email address that gets notified?

Thanks,

Imar


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Imar,

Index builds usually fails due to incorrect data in the database -- most likely because of an import of bad data. If this is not the case, then the log file should give you an idea as to why it happens. Could you post the Log.log and Status.xml files from a build that failed?

Also, it's a good idea to make sure you're on a reasonably new version of Dynamicweb; I'd recommend at least 8.7.2 or newer.

With regard to notifications, then no, there are no notifications in the Indexing API. The reason for this is a technical one. The Notification API exists in the Dynamicweb assembly and this is also where a lot of the content APIs sit, e.g. Ecommerce and Users. These APIs have to be able to reach the Indexing API, which sits in a separate assembly. Therefore, it's not possible for the Indexing API to reach the Notification API without a cyclic reference occurring. I can pretty much guarantee that for the current branch of Dynamicweb, this will not change.

There is a way to do something else though. You can check the current state of a build by asking the TaskManager or you can ask the IndexHelper.IsInstanceAvailable whether a specific instance is available (requires 8.7.2.3). If an instance is unavailable, asking IndexHelper.IsInstanceAvailable does not tell you why it's unavailable only that it is. Using the TaskManager can give you the most information, but also requires the most custom code. You can see this post http://developer.dynamicweb.com/forum/development/new-indexing-documentation.aspx#Reply42202 to give you some ideas on working with the TaskManager. You still need something like a Scheduled Task that can run your code periodically to check the state of the build.

- Jeppe

 
Peter Leleulya
Reply

I've more or less the same problem.
I build the (new) index after a custom import action and once in a while it fails or seems to be 'stuck' ...
I obviously end up with a site with no products and when I manually run the index it always succeeds ...

This is what I do, I fire the index build and forget:

var indexService = ServiceLocator.Current.GetInstance<IIndexService>();
indexService.BuildIndex(repositoryName, indexName, instance, build);

I would like some functionality that checks if the index build succeeded,
- if not, retry a number of times (eventually call some function that alerts me if no retry succeeded)
- if so, build the second instance, also with the retry meganism ...

Is there a way in code to achieve this, without using a scheduled task?


 

 
Nicolai Høeg Pedersen
Reply

Hi Peter

In 8.8.1.0 the indexing works a bit different. If you have 2 instances and the build fails, it will stop the indexing and leave instance 2 available so you do not run out of product data.

in 8.9 you will get email notifications (TFS#22904) - it will support sending mails on success, warnings and errors respectively.

BR Nicolai

 
Peter Leleulya
Reply

Ok, this site is currently on 8.8.0.2, which does leave me with a site with no products.
The notification is a nice addition, but I'm looking for some retry meganism and a way to update the second instance (only when updating the first succeeded) ...
Is there a way to know if a non scheduled index update succeeded.
For example is there a log file which I can read after enough time to know if the build succeeded and work with that ...
Or is there some other clever way to achieve this?

 
Nicolai Høeg Pedersen
Reply

Hi Peter

I will see if retry makes sense and have it implemented as a core fetaure.

You can find information on the builds and instances from the Tracker that is used by the TaskManager when Dynamicweb builds the indexes.

This is the code we use to get the status of instances - it relies on information you can find in \Files\System\Diagnostics\* folders where all activity regarding the indexing process is stored. The code below will use our API to locate the status and return status and timestamps related to the build.

Dim indexingService As IIndexService = ServiceLocator.Current.GetInstance(Of IIndexService)()
        Dim repositoryName As String = repository
        Dim index As IIndex = indexingService.LoadIndex(repositoryName, item + ".index")
        Dim supportsResume As Boolean = index.Builds.Count > 0 AndAlso (TypeOf index.Builds.ElementAt(0).Value Is IResumable)

        Dim statuslist As New Dictionary(Of String, Object)

        For Each instance As IIndexProvider In index.Instances.Values

            Dim taskname As String = String.Format("{0}#{1}#{2}", repositoryName, index.Name, instance.Name)
            Dim trackerPath As String = Path.Combine(repositoryName, item + ".index", instance.Name)
            Dim history As IEnumerable(Of Status) = Tracker.GetStatusHistory(trackerPath, 2)
            Dim currentStatus As Status
            Dim lastStatus As Status = Nothing
            Dim taskIsActive As Boolean = TaskManager.IsTaskActive(taskname)

            If taskIsActive Then
                currentStatus = TaskManager.GetTaskInfo(taskname).Value.Tracker.Status
            Else
                currentStatus = history.FirstOrDefault
            End If

            If history.Count() = 2 Then
                lastStatus = history(1)
            End If

            Dim res As Object = New With {
                .IsActive = taskIsActive,
                .Status = currentStatus,
                .LastStatus = lastStatus,
                .Resumable = supportsResume
            }

            statuslist.Add(instance.Name, res)

        Next

        Return statuslist

 

 

 

You must be logged in to post in the forum