Passing the delay to the retry_query function allows the same function to be used in all cases. This removes duplicate code.