Delay in writing changes to DB

We have non-nuxeo code that reads documents directly from the database. We fire this code (that updates a lucene index) based on nuxeo events (eg “document created”). In other places, we manually fire the non-nuxeo code with a 1 second delay.

In both cases, we are finding that often there is a significant lag between when we expect nuxeo to have written to the db, and the the changes actually being written.

Is there a way we can guarantee that our “other” code executes AFTER nuxeo has committed changes to the database? Any solution would do - eg a callback, changing a setting, anything.

We are using Nuxeo 5.3 and postgres 8.3. Upgrading nuxeo is not a viable option at the moment.

EDITED:

It seems I can not answer my own question, so I'll edit it here instead with how I solved this problem:

ACCEPTED ANSWER:

I solved this not by implementing PostCommitEventListener (and adding code that did not add any more value), but rather by setting postCommit="true" on my existing event listeners in listener-contrib.xml . That fixed everything.

1 votes

1 answers

767 views

ANSWER



You should fire this code from an event listener that implements the PostCommitEventListener interface. This will only be called once the database has successfully committed the transaction hence rendered the changes visible to new transactions that starts after the commit.

For instance in Nuxeo the JmsEventForwarder class implements that interface to avoid the problems you mention.

2 votes