diff --git a/src/api-service/__app__/timer_workers/__init__.py b/src/api-service/__app__/timer_workers/__init__.py index 5f30cbf1a..81e49a567 100644 --- a/src/api-service/__app__/timer_workers/__init__.py +++ b/src/api-service/__app__/timer_workers/__init__.py @@ -28,6 +28,17 @@ def process_scaleset(scaleset: Scaleset) -> None: def main(mytimer: func.TimerRequest, dashboard: func.Out[str]) -> None: # noqa: F841 + # NOTE: Update pools first, such that scalesets impacted by pool updates + # (such as shutdown or resize) happen during this iteration `timer_worker` + # rather than the following iteration. + pools = Pool.search() + for pool in pools: + if pool.state in PoolState.needs_work(): + logging.info("update pool: %s (%s)", pool.pool_id, pool.name) + process_state_updates(pool) + elif pool.state in PoolState.available() and pool.autoscale: + autoscale_pool(pool) + Node.mark_outdated_nodes() nodes = Node.search_states(states=NodeState.needs_work()) for node in nodes: @@ -38,14 +49,6 @@ def main(mytimer: func.TimerRequest, dashboard: func.Out[str]) -> None: # noqa: for scaleset in scalesets: process_scaleset(scaleset) - pools = Pool.search() - for pool in pools: - if pool.state in PoolState.needs_work(): - logging.info("update pool: %s (%s)", pool.pool_id, pool.name) - process_state_updates(pool) - elif pool.state in PoolState.available() and pool.autoscale: - autoscale_pool(pool) - events = get_events() if events: dashboard.set(events)