So out of existential need, I intentionally starting taking on large, creative projects at work that I knew would hold my interest and consume my thoughts. In some cases, this meant undertaking projects of my own volition and "asking for forgiveness rather than permission" at work.
In part because of a couple of articles I read on the scientifically shown improvement of outcomes of cancer patients with positive attitudes, and because I knew my mom already had several negative voices around her daily, I decided my role with her would be relentlessly positive.
An attitude of "we don't know the future, all things are possible, and anything can be overcome with the right set of inputs -- we just need to find what those are". I quickly adopted this attitude for myself, and it allowed me to embrace failure more - because the attitude wasn't predicated on being the best, but rather of overcoming.
Granted, this was all about 6 years ago. Since then, much has changed, and I do find myself facing similar issues again. Without the presence of something "existential" pushing me, I am finding it harder to overcome this time myself.
As with most things, though, feedback cycles are a thing. Negativity feeds on itself, and success begets success, so the first step is finding whatever you can to help break the feedback loop. Catch any negative thoughts as quickly as you can, and redirect them from fatalistic into something malleable.
Catch any random, distracting "I need to Google this" type thoughts as they happen, and write them down on a notebook as something you should Google later, but not right now.
One important thing at the start is that, you don't have to necessarily believe every positive mantra or habit you say, you just have to do it. Over time, the believability will come on its own.
If you can get momentum going towards the positive instead of the negative, break the feedback loop, and get onto the "success begets success" side of it, it gets much easier.
Hope that helps and makes sense. Wish I had an actual, easy answer, but a lot of it is just trying things until you see what works, and being consistent above all else.
Good luck, and if you come up with any of your own tips, please let me know, because as I said - for as much as I've been through this before successfully, I can see it happening again, and I'm realizing it's time to deal with it again myself.
So much so that I ended up writing a queueing app for scheduling batches of sequential tasks on the server in Dart just to see how it could work as a NodeJS replacement, and thought the whole dev experience was great.