We are doing some data warehouse stuff based on Phalcon. So there are high concurrent processes writing into MySQL. Sometimes, at different points of code, a deadlock occurs. So my question is, if it's possible to create a general middleware/listener for ORM/PDO to re-try the executed statements and fail not until 3 retries?