It's not when you're tired. It's not when you've failed and are failing. It's not even when you realize the goal is impossible.
You should quit when you have become someone you don't want to be.
But if you are who you want to be, then don't quit, because success and failure are irrelevant. No matter what happens, making decisions and taking actions centered on the type of person you wish to be is exactly what you need to continue doing.