Typically you need ten years to retire with flight benefits.
For a pension or medical benefits, for the few that still have them, it would be specific to the company.
How much time do you need to make it worthwhile? If you're gainfully employed, probably 10-15 years. Maybe less if you want money more than QOL. Maybe way less if you just want to punch a bucket list ticket. Heard of guys getting hired at age 63.