Longitudinal Ramsey spectroscopy of atoms for continuous operation of optical clocks