I have been having this issue for some months now, but it has been present for a long time.
Basically, I can't make me to focus on my work until it's really close to the deadline of my task or even later. I keep procrastinating or code other things, but the one task that I know is my highest priority and the one that should be done, always gets ignored until last minute.
The weird thing is that even when I took a break from full-time work for a year or so, I eventually got to the point that even for my own (low or high importance) projects I would do the same and procrastinate instead of working on the project that I know I must work on to accomplish my goals. I think I generally do this not only on code stuff though. Anyone else had this?
Maybe that was in high school or college, or during your first few years in your career. Ask yourself: What was different back then? What was your daily routine? What did you eat? Did you play sports or stay active?
A lot of people suffer from low dopamine levels. You've essentially trained your brain to crave short term reward vs long term reward, which affects your attention span and ability to focus on anything that doesn't provide instant gratification.
http://mentalhealthdaily.com/2015/04/02/low-dopamine-levels-...
Get enough sleep, exercise every day, clean up your diet, stop fapping, don't drink for a while, detox from caffeine, try meditation.
You want a radical lifestyle change to rewire your brain and fix any chemical imbalances and/or dietary issues you might have.
Attack from all angles!
Your life will change in a matter of weeks if not days.