Flush sql statements from cache to DB before calling a procedure

Hi, I have a use case, where I am implementing my own HistoryEventHandler, where on process end event I want to call some stored procedure. However, for the procedure to work properly, all of the pending sql statements, that have not been flused to DB be flushed. Is there any way to invoke flush manually?

I am using camunda spring boot. I have been googling for some time and could not find any working sollution.

Hi,

If you make the end event async before, as least process state up tio that point will be flushed to the DB. The end event of course will not be flushed…
regards

Rob

I need everything to be flushed, the procedure is marking all the history data relevant to the process for partitioning.

I could of course use custom batch jobs for that, but with this solution arises, I have similar procedure for batches. So I would have to make exception for batch jobs that are doing the partitioning stuff. And if I do that, then I would need to clean these partitioning jobs regularly so they do not stay in the db. Quite a lot of stuff because I cannot make a simple flush externally.

OK, so I have been digging and was able to trigger flush manually with following code:

Context.getCommandContext().getDbEntityManager().flush();

however, it does not work, as it fails on CommandContext close afterwards, because DbEntityManager is implemented in a way, that when DbEntityManager.flush() method is called, it does not clean the cache. It seems that nobody event thought of my use case, or from some reason, it would break things.

So my question is, is there some workaround for this, or do I really have use batch jobs for this. Another possibility could be AOP, but defining correct jointpoint would be quite tricky and probably not very nice solution too.

Hi @tomorrow,

please don’t flush the transaction by your own :skull_and_crossbones: This lead to problems in the engine.

You could use a TransactionListener to do stuff after the engine transaction is committed.

TransactionListener transactionListener = commandContext -> {
	// do stuff
};
Context.getCommandContext().getTransactionContext().addTransactionListener(TransactionState.COMMITTED, transactionListener);

Does this help you?

Best regards,
Philipp

Thanks, I haven’t known about transaction listener yet. Although it would be too complicated as I wanted to add a hook on process end via custom HIstoryEventHandler, which is inside the transaction and would need to register somewhere the information aboud process end, where it would be readable by transaction listener, which starts to be a little complicated instead of making things more straighforward as opossed to other possiblities.

However, the transaction listener might come handy in other use cases.