code: def __init__(
      self,
      app,
      pool: Pool,
      async_worker_pool: AsyncWorkerPool,  # BORROWED
      task_manager: aiotools.BackgroundTaskManager,  # BORROWED
  ):
      self.app = app
      self.scheduler_state_changed = pool.scheduler_state_changed
      self.db: Database = app["db"]
      self.pool = pool
      self.async_worker_pool = async_worker_pool
      self.exceeded_shares_counter = ExceededSharesCounter()
      task_manager.ensure_future(
          retry_long_running(
              "schedule_loop",
              run_if_changed,
              self.scheduler_state_changed,
              self.schedule_loop_body,
          )
      )
  
imports: import asyncio
  import logging
  import random
  from collections import defaultdict
  from typing import Dict, List, Optional, Tuple
  import prometheus_client
  import sortedcontainers
  from gear import Database
  from hailtop import aiotools
  from hailtop.utils import AsyncWorkerPool, Notice, WaitableSharedPool, periodically_call_with_dynamic_sleep, retry_long_running, run_if_changed, secret_alnum_string, time_msecs
  from ...batch_format_version import BatchFormatVersion
  from ...globals import INSTANCE_VERSION
  from ...inst_coll_config import PoolConfig
  from ...utils import ExceededSharesCounter, regions_bits_rep_to_regions
  from ..instance import Instance
  from ..job import mark_job_errored, schedule_job
  from ..resource_manager import CloudResourceManager
  from .base import InstanceCollection, InstanceCollectionManager
label_desc: Use image node_id 1 to create a new PoolScheduler object  with example: obj = PoolScheduler(app, pool, async_worker_pool, task_manager)