Note that gravitational and thermal distortions coupled - a perfect 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 the change and 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 a synthesis is to observe in a hybrid array - hybrid arrays allow a synthesis to be performed without the need to track the source from horizon to horizon.
The 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 so they are at significantly different parts of the sky (ie significantly different azimuths). Unless the sky is cloudy, being at different azimuths is not important.