How to retry transactions on command line scripts

I have some command line scripts -- the kind you run with "bin/instance run" -- and sometimes when I run them I have conflict errors while trying to commit the transaction. It occurs because there are other users managing content on the site simultaneously.

My question is: how to implement the same retry mechanism that Plone uses when handling the regular requests. I want my script to behave as if the code is being executed in a view, for example.

You could use dm.zodb.asynchronous. Its transactional module contains a transactional decorator which handles transactions similar to the way of Zope/Plone (i.e. with retrieal in case of ConflictError). It comes with a simple example.


It seems to work. Thank you!