If you’ve been saying “come” to your dog for years, and sometimes he does it and sometimes he doesn’t, the word “come” may have lost it’s meaning. It certainly doesn’t have the effect you want it to. Choose another word, and start teaching your dog the command from scratch. I like to use “here”.
This time, make sure you never ask your dog to do the command unless you can guarantee he will do it. For example, don’t say “here” unless your dog is on a leash or in a small space where you can make him complete the command. And then make sure to reward him, with treats, toys or play and praise.
When a dog has learned to ignore a command or cue it’s called Learned Irrelevance. Read more about it here: