class_docstr: A registry for task schedulers.
class_docstr_tok: ["A","registry","for","task","schedulers","."]
docstr: Creates a task scheduler for the given task.
  
  The task is matched as follows:
  1. The node type name of the node associated with the task is looked up in
     the registry.
  2. Next, the executor spec url of the node (if one exists) is looked up in
     the registry. This assumes deployment_config packed in the pipeline IR is
     of type `IntermediateDeploymentConfig`.
  3. If a url is matched in the previous two steps, the associated task
     scheduler class constructor or builder is called and an instantiated task
     scheduler object is returned.
  4. Lastly, a ValueError is raised if no match can be found.
  
  Args:
    mlmd_handle: A handle to the MLMD db.
    pipeline: The pipeline IR.
    task: The task that needs to be scheduled.
  
  Returns:
    An instance of `TaskScheduler` for the given task.
  
  Raises:
    NotImplementedError: Raised if not an `ExecNodeTask`.
    ValueError: If a scheduler class or builder could not be found in the
      registry for the given task, or the building fails.
docstr_tok: ["Creates","a","task","scheduler","for","the","given","task",".","The","task","is","matched","as","follows",":","1",".","The","node","type","name","of","the","node","associated","with","the","task","is","looked","up","in","the","registry",".","2",".","Next",",","the","executor","spec","url","of","the","node","(","if","one","exists",")","is","looked","up","in","the","registry",".","This","assumes","deployment_config","packed","in","the","pipeline","IR","is","of","type","`","IntermediateDeploymentConfig","`",".","3",".","If","a","url","is","matched","in","the","previous","two","steps",",","the","associated","task","scheduler","class","constructor","or","builder","is","called","and","an","instantiated","task","scheduler","object","is","returned",".","4",".","Lastly",",","a","ValueError","is","raised","if","no","match","can","be","found",".","Args",":","mlmd_handle",":","A","handle","to","the","MLMD","db",".","pipeline",":","The","pipeline","IR",".","task",":","The","task","that","needs","to","be","scheduled",".","Returns",":","An","instance","of","`","TaskScheduler","`","for","the","given","task",".","Raises",":","NotImplementedError",":","Raised","if","not","an","`","ExecNodeTask","`",".","ValueError",":","If","a","scheduler","class","or","builder","could","not","be","found","in","the","registry","for","the","given","task",",","or","the","building","fails","."]
code: def create_task_scheduler(
      cls: Type[T],
      mlmd_handle: metadata.Metadata,
      pipeline: pipeline_pb2.Pipeline,
      task: task_lib.Task,
  ) -> TaskScheduler:
      """Creates a task scheduler for the given task.
  
      The task is matched as follows:
      1. The node type name of the node associated with the task is looked up in
         the registry.
      2. Next, the executor spec url of the node (if one exists) is looked up in
         the registry. This assumes deployment_config packed in the pipeline IR is
         of type `IntermediateDeploymentConfig`.
      3. If a url is matched in the previous two steps, the associated task
         scheduler class constructor or builder is called and an instantiated task
         scheduler object is returned.
      4. Lastly, a ValueError is raised if no match can be found.
  
      Args:
        mlmd_handle: A handle to the MLMD db.
        pipeline: The pipeline IR.
        task: The task that needs to be scheduled.
  
      Returns:
        An instance of `TaskScheduler` for the given task.
  
      Raises:
        NotImplementedError: Raised if not an `ExecNodeTask`.
        ValueError: If a scheduler class or builder could not be found in the
          registry for the given task, or the building fails.
      """
  
      if not isinstance(task, task_lib.ExecNodeTask):
          raise NotImplementedError(
              "Can create a task scheduler only for an `ExecNodeTask`."
          )
  
      try:
          scheduler_cls_or_builder = (
              cls._scheduler_cls_or_builder_for_node_type(task)
          )
      except ValueError as e1:
          try:
              scheduler_cls_or_builder = (
                  cls._scheduler_cls_or_builder_for_executor_spec(
                      pipeline, task
                  )
              )
          except ValueError as e2:
              raise ValueError(
                  f"No task scheduler class or builder found: {e1}, {e2}"
              ) from None
  
      try:
          task_scheduler = scheduler_cls_or_builder(
              mlmd_handle=mlmd_handle, pipeline=pipeline, task=task
          )
      except ValueError as e:
          raise ValueError(
              "Associated scheduler builder failed to build a task scheduler."
          ) from e
  
      return task_scheduler
  
imports: import abc
  from typing import Callable, Dict, Generic, List, Optional, Type, TypeVar, Union
  import attr
  from tfx import types
  from tfx.orchestration import metadata
  from tfx.orchestration.experimental.core import task
  from tfx.proto.orchestration import execution_result_pb2
  from tfx.proto.orchestration import pipeline_pb2
  from tfx.utils import status
label_desc: Use image node_id 3 for calling the TaskSchedulerRegistry obj's underlying member method code with example usage: obj.create_task_scheduler(cls, mlmd_handle, pipeline, task) and returns: task_scheduler