If you ask within 10 minutes before the start of Mass, be prepared to be turned down. Some priests will, some won’t. I’d try to ask 30 minutes or so out from the start of Mass. Right before Mass is a busy time and we’re usually trying to make sure all the personnel are in place and everything is set up.
As for the “rules,” Canon 843 says the faithful have a right to the sacraments if they are properly disposed, not legally impeded, and ask in a timely manner. If you knock on the rectory door at 3 AM to go to Confession and you’re not actually dying, I’m within my rights to turn you away. If you ask me five minutes before Mass, I don’t usually consider that timely, and will simply ask you to wait till afterward. Receiving communion is good, but not required, and it would be better to have you make a good Confession where neither of us feels rushed.
-Fr ACEGC