Part of my bad mood often comes from the fact that I have something in my head which prevents me from focusing on the present.
It can be a personal project I'm working on, work related matters, events coming up that make me nervous etc...
What do you do to let go of these without loosing progress?
Do you also feel frustrated to stop working on something before it is finished?
One is being interrupted, the other is being distracted. Being interrupted is external, while being distracted is internal.
So which one is it you're having problems with?
Personally, I have come to accept that there will be interruptions. Colleagues asking for help, someone asking a question, some boss calling an unexpected meeting, my mother phoning or whatever. Some of these you can avoid; like you could have a rule to always communicate meetings in advance. But at least a part of these will be unavoidable. How many depends on particular circumstances; e.g. being a senior engineer in a mostly junior group means you were specifically hired to be interrupted to a considerable extent.
One thing that sometimes helps me with interruptions is using 5-10 seconds. That is, when someone comes I just ask for 10 seconds, I make a gesture or simply say "10 seconds" or whatever, and then proceed to sort of "unload". I write down the precise point I am at and the exact upcoming action I was going to take.
On the matter of distractions, it depends a lot more on yourself and the success of anything you try will be very dependent on how you are.
In this front, one thing I do is scheduling. I want/need to do X... but I have to do Y now. So, I slot it into an appropriate time. e.g. "This weekend I want to make progress on that personal project". So "this weekend". This means: a. not now, and b. I have sort of secured a time for it, I don't have to worry about it because it has an assigned place.
Again, in this area what works for others may not work for you. But also, as someone has already mentioned, if you can't manage to learn how to do this on your own, reaching out to a therapist or other professional help is a valid solution. They may provide more specific tools and techniques.