Good fingering requires analysis of the entire passage and a fair bit of problem solving. It is important to keep in mind not only the notes you are playing, but also the notes that are coming. A really good fingering for a few notes might make finding a good fingering for the next few challenging or even impossible. Sometimes it helps to work backward.
Looking at the first three notes of your example, I would absolutely use 5-2-1 (since 2 and 1 can span about as much distance as 5 and 2)
I would play the next three exactly the same if it weren't for the next note (E4). Since we now have a new destination we need to reconsider our route to get there. Frankly, in this situation, we have a couple valid choices:
1) 5-2-1-2: reuse the fingering from the first three notes (5-2-1), but cross over your 1st finger on B3 and play E4 with your 2nd or 3rd
2) 5-1-2-1: use 5-1 for your first two notes (instead of 5-2), cross over your 1st and use your 2nd on B3 and your 1st on E4
Finally, adding on the additional E3 from your second example, we now need to make sure that everything preceding it leads us to a position that allows us to comfortably move down the octave from E4. Arriving at E4 on 2nd or 3rd, from the first option above, makes this difficult, but using the second option and playing E4 with our 1st leads perfectly into playing the final E3 with our 5th.
So, in the end, it was the last finger that determined the rest. Essentially, each finger affected all those leading up to it. (You can see, I'm sure, why working backwards can help.)
And, after all that, we end up with the following fingering: 5-2-1-5-1-2-1-5
(Also note that if we instead want to go up to A4 instead of down to E3 we can simply use the first option above, land on E4 with our 2nd or 3rd and easily reach A4 with our 1st (5-2-1-5-2-1-3-1); to change just the last note we had to adjust the fingering for the entire second half!)