How to pause programmatically after creating a Sitecore element before updating the index

An employee asked this question, and I did not immediately find a solution, so I post it here. It programmatically inserts a Sitecore element into the main database, and then subsequently has to insert another element that is dependent on the first element present in the index. Initially, he had an insert of the second insert every time or two, but since then he inserted a manual pause in his code to try to catch up with the index time, and now he fails only about the tenth time. Better, but not perfect.

He is looking for a way for Sitecore to check whether the index is updated before it starts to insert the dependent element.

I found this blog post by Alex Shyba ( http://sitecoreblog.alexshyba.com/2011/04/search-index-troubleshooting.html ), which looks like it might have some applicability, but my colleague is strictly working in the main The database (without publication), and we already have the first few steps in the Alex article implemented in our solution (I did not go through all this).

+4
source share
3 answers

If you depend on adding an index, after all, the only way to guarantee that the element is in the index is to take the action after updating the asynchronous index. And in Sitecore 6, the only way to do what I know is database:propertychanged event . Alex Shyba describes this event in another article regarding clearing the HTML cache.

Your task will probably know in the event handler which element was inserted and what to do with it. You will need some kind of global data structure to convey this status information, since updating the index is done as asynch work.

Other options (which could be simpler) are to remove the dependency on updating the index (use a Sitecore query or a quick query) or poll the index until the element is gone (which is a bit ugly).

+2
source

Why not just add the item yourself? Thus, the user interface will be blocked until it is completed.

You can do this by connecting to the element: saved event. I think the event handler will be based on the code from the database crawler

+2
source

Have you thought about the priority of the second task as a “timed task”, with some kind of shell for checking the dependency and the need, if necessary? See http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2010/11/All-About-Sitecore-Scheduling-Agents-and-Tasks.aspx .

0
source

All Articles