Make MySQL function async and stop lottery from cancelling tasks