diff --git a/adaptive_scheduler/observations.py b/adaptive_scheduler/observations.py index 36ab484..291913d 100644 --- a/adaptive_scheduler/observations.py +++ b/adaptive_scheduler/observations.py @@ -339,8 +339,13 @@ def _get_running_observations(self, ends_after, starts_before, site, obs, tel): cutoff_dt = starts_before for observation in schedule: if observation['start'] < starts_before < observation['end']: - if observation['end'] > cutoff_dt and observation['state'] in ['PENDING', 'IN_PROGRESS']: - cutoff_dt = observation['end'] + if observation['end'] > cutoff_dt: + if observation['state'] in ['PENDING', 'IN_PROGRESS']: + cutoff_dt = observation['end'] + elif observation['state'] == 'COMPLETED': + # If the observation is already completed, set its end time so we don't block + # scheduling other observations using that end time as a reason + observation['end'] = starts_before running = [b for b in schedule if b['start'] < cutoff_dt]