Developer forum

Forum » Development » Building Indexes on Application Start

Building Indexes on Application Start

Joseph Vause
Reply

Hello,

 

Is there a way to programmatically get a list of all the indexes, and build it when the application starts up? Using Docker Containers means every time we release it would require manual intervention to rebuild the indexes. Ideally we want to get to a point where we can add indexes to the health check, so only switch to the new instance once all indexes are built and ready.

 

Thanks


Replies

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Josheph,

 

You can subscribe to the Application.AfterStart notification and then call Dynamicweb.Indexing.IndexHelper.BuildIndexInstances().

 

Assuming they are small and only take a few seconds each, you should be fine. If you have large indexes that take multiple minutes to complete, you may see this taking even longer. We've experienced that concurrent builds take longer to complete than if they were triggered in sequence (one at a time).

 

Here's a quick example on how to subscribe to it

using Dynamicweb.Extensibility.Notifications;
 
namespace MyNamespace
{
    [Subscribe(Dynamicweb.Notifications.Standard.Application.AfterStart)]
    public class ApplicationStart : NotificationSubscriber
    {
        public override void OnNotify(string notification, NotificationArgs args)
        {
            if (!(args is Dynamicweb.Notifications.Standard.Application.AfterStartArgs myArgs))
            {
                return;
            }
 
            // your code here
        }
    }
}

 

Best Regards,

Nuno Aguiar

 
Joseph Vause
Reply

Hello,

Thanks for the response, unfortunately that Notification is obsolete, and it comes up with Dynamicweb.Notifications.Standard.Application' is obsolete: 'Do not use' 

We have found an alternative solution using a hosted service.

 

Thanks

 

You must be logged in to post in the forum