SyliusElasticsearchPlugin icon indicating copy to clipboard operation
SyliusElasticsearchPlugin copied to clipboard

Updating Elasticsearch from a Messenger worker does not happen

Open mvriel opened this issue 5 years ago • 0 comments

In one of the projects I am working on, I noticed that when we sync products from a PIM to Sylius (using Symfony Messenger) that the Elasticsearch index is not updated.

After research, it became clear this had to do with the Elastica listener as it only flushes updated onTerminate. But workers run as daemons, and as such the changes were never pushed.

Our solution:

I have tried to solve this by adding an extra listener that uses the MessageHandled event, but the onTerminate function disables the 'defer' config option when invoked. Thus the first pass will defer all updates, but the subsequent runs of the daemon do not.

In addition, we had to add a rollback mechanism since the doctrine transaction middleware was enabled; for which this listener also does not have support.

In the end, we copied the elastica listener and re-set the defer config entry in onTerminate, and added a rollback method that would clear the queues in the listener.

Aside from having a listener like this in this project being nice, I also think that the lack of elastic updates is a bug that can trip up people when using Symfony Messenger or other daemon-based implementations.

mvriel avatar May 07 '20 08:05 mvriel