Note that gravitational and thermal distortions can be coupled - perfect measurement or correction for these effects is never possible.
To first order, the gain change will be calibrated out provided the secondary calibrator is very close to the target source. Applying the standard gain/elevation curve to the data as the first step in the data reduction will also help. However these two steps will not account for changes in the beamshape. This might be an important effect for widefield imaging and mosaicing.
The best way to avoid thermally-induced gain variations is by observing in the pre-dawn hours or on a calm cloudy day. The best way to avoid large elevation changes in an observation is to observe in a hybrid array - hybrid arrays allow an observation to be performed without the need to track the source from horizon to horizon.
Gain variations must be considered when bootstrapping the flux density scale. The best approach to ensuring a good flux scale is to ensure that the secondary and the flux density calibrator are observed nearly simultaneously and at the same elevation. Although this may at first glance sound difficult if not impossible, generally it is straightforward. Generally there should be a time when the secondary and the flux density calibrator are at the same elevation. It may be that one is rising while the other is setting, and that they are at significantly different parts of the sky (i.e. significantly different azimuths). Unless the sky is cloudy, being at different azimuths is not important.