You can refer to the available literature on the topic. The papers I am aware of are:
Ray Tracing in Non-Constant Media
and
Refractive radiative transfer equation
The general algorithm for handling a varying index of refraction is ray-marching, where the size of the steps is related to the accuracy of your solution.