The life-cycle of star formation in distant clusters