Whenever I'm in the mood and have time. Sometimes it's right after a trip to a range (as little as 100-200 rounds) and sometimes as long as 1-2K rounds. As long as it lubed properly a little grime isn't going to stop a glock from running or cause malfunctions.
Heck, I know a guy that ran 13K+ rounds through his M&P before cleaning. This was the dirtiest gun I've ever seen. During that few month period he only lubed the gun a few times and never had one failure. While this isn't something you should do with your carry gun, it just goes to show you if you have a good gun, a little bit of crap isn't likely to cause failures.
However, dirty mags can lead to problems from being dropped in the dirt, mud, etc. That's why it's important to have separate mags for training and carrying.