class_docstr: Starts flex templates with the Dataflow pipeline.
  
  .. seealso::
      For more information on how to use this operator, take a look at the guide:
      :ref:`howto/operator:DataflowStartFlexTemplateOperator`
  
  :param body: The request body. See:
      https://cloud.google.com/dataflow/docs/reference/rest/v1b3/projects.locations.flexTemplates/launch#request-body
  :param location: The location of the Dataflow job (for example europe-west1)
  :param project_id: The ID of the GCP project that owns the job.
  :param gcp_conn_id: The connection ID to use connecting to Google Cloud
      Platform.
  :param drain_pipeline: Optional, set to True if want to stop streaming job by draining it
      instead of canceling during killing task instance. See:
      https://cloud.google.com/dataflow/docs/guides/stopping-a-pipeline
  :param cancel_timeout: How long (in seconds) operator should wait for the pipeline to be
      successfully cancelled when task is being killed.
  :param wait_until_finished: (Optional)
      If True, wait for the end of pipeline execution before exiting.
      If False, only submits job.
      If None, default behavior.
  
      The default behavior depends on the type of pipeline:
  
      * for the streaming pipeline, wait for jobs to start,
      * for the batch pipeline, wait for the jobs to complete.
  
      .. warning::
  
          You cannot call ``PipelineResult.wait_until_finish`` method in your pipeline code for the operator
          to work properly. i. e. you must use asynchronous execution. Otherwise, your pipeline will
          always wait until finished. For more information, look at:
          `Asynchronous execution
          <https://cloud.google.com/dataflow/docs/guides/specifying-exec-params#python_10>`__
  
      The process of starting the Dataflow job in Airflow consists of two steps:
  
      * running a subprocess and reading the stderr/stderr log for the job id.
      * loop waiting for the end of the job ID from the previous step.
        This loop checks the status of the job.
  
      Step two is started just after step one has finished, so if you have wait_until_finished in your
      pipeline code, step two will not start until the process stops. When this process stops,
      steps two will run, but it will only execute one iteration as the job will be in a terminal state.
  
      If you in your pipeline do not call the wait_for_pipeline method but pass wait_until_finish=True
      to the operator, the second loop will wait for the job's terminal state.
  
      If you in your pipeline do not call the wait_for_pipeline method, and pass wait_until_finish=False
      to the operator, the second loop will check once is job not in terminal state and exit the loop.
  :param impersonation_chain: Optional service account to impersonate using short-term
      credentials, or chained list of accounts required to get the access_token
      of the last account in the list, which will be impersonated in the request.
      If set as a string, the account must grant the originating account
      the Service Account Token Creator IAM role.
      If set as a sequence, the identities from the list must grant
      Service Account Token Creator IAM role to the directly preceding identity, with first
      account from the list granting this role to the originating account (templated).
  :param deferrable: Run operator in the deferrable mode.
  :param expected_terminal_state: The expected final status of the operator on which the corresponding
      Airflow task succeeds. When not specified, it will be determined by the hook.
  :param append_job_name: True if unique suffix has to be appended to job name.
class_docstr_tok: ["Starts","flex","templates","with","the","Dataflow","pipeline",".","..","seealso",":",":","For","more","information","on","how","to","use","this","operator",",","take","a","look","at","the","guide",":",":","ref",":","`","howto\/operator",":","DataflowStartFlexTemplateOperator","`",":","param","body",":","The","request","body",".","See",":","https",":","\/\/cloud.google.com\/dataflow\/docs\/reference\/rest\/v1b3\/projects.locations.flexTemplates\/launch","#","request-body",":","param","location",":","The","location","of","the","Dataflow","job","(","for","example","europe-west1",")",":","param","project_id",":","The","ID","of","the","GCP","project","that","owns","the","job",".",":","param","gcp_conn_id",":","The","connection","ID","to","use","connecting","to","Google","Cloud","Platform",".",":","param","drain_pipeline",":","Optional",",","set","to","True","if","want","to","stop","streaming","job","by","draining","it","instead","of","canceling","during","killing","task","instance",".","See",":","https",":","\/\/cloud.google.com\/dataflow\/docs\/guides\/stopping-a-pipeline",":","param","cancel_timeout",":","How","long","(","in","seconds",")","operator","should","wait","for","the","pipeline","to","be","successfully","cancelled","when","task","is","being","killed",".",":","param","wait_until_finished",":","(","Optional",")","If","True",",","wait","for","the","end","of","pipeline","execution","before","exiting",".","If","False",",","only","submits","job",".","If","None",",","default","behavior",".","The","default","behavior","depends","on","the","type","of","pipeline",":","*","for","the","streaming","pipeline",",","wait","for","jobs","to","start",",","*","for","the","batch","pipeline",",","wait","for","the","jobs","to","complete",".","..","warning",":",":","You","can","not","call","``","PipelineResult.wait_until_finish","``","method","in","your","pipeline","code","for","the","operator","to","work","properly",".","i.","e.","you","must","use","asynchronous","execution",".","Otherwise",",","your","pipeline","will","always","wait","until","finished",".","For","more","information",",","look","at",":","`","Asynchronous","execution","<","https",":","\/\/cloud.google.com\/dataflow\/docs\/guides\/specifying-exec-params","#","python_10",">","`","__","The","process","of","starting","the","Dataflow","job","in","Airflow","consists","of","two","steps",":","*","running","a","subprocess","and","reading","the","stderr\/stderr","log","for","the","job","id",".","*","loop","waiting","for","the","end","of","the","job","ID","from","the","previous","step",".","This","loop","checks","the","status","of","the","job",".","Step","two","is","started","just","after","step","one","has","finished",",","so","if","you","have","wait_until_finished","in","your","pipeline","code",",","step","two","will","not","start","until","the","process","stops",".","When","this","process","stops",",","steps","two","will","run",",","but","it","will","only","execute","one","iteration","as","the","job","will","be","in","a","terminal","state",".","If","you","in","your","pipeline","do","not","call","the","wait_for_pipeline","method","but","pass","wait_until_finish=True","to","the","operator",",","the","second","loop","will","wait","for","the","job","'s","terminal","state",".","If","you","in","your","pipeline","do","not","call","the","wait_for_pipeline","method",",","and","pass","wait_until_finish=False","to","the","operator",",","the","second","loop","will","check","once","is","job","not","in","terminal","state","and","exit","the","loop",".",":","param","impersonation_chain",":","Optional","service","account","to","impersonate","using","short-term","credentials",",","or","chained","list","of","accounts","required","to","get","the","access_token","of","the","last","account","in","the","list",",","which","will","be","impersonated","in","the","request",".","If","set","as","a","string",",","the","account","must","grant","the","originating","account","the","Service","Account","Token","Creator","IAM","role",".","If","set","as","a","sequence",",","the","identities","from","the","list","must","grant","Service","Account","Token","Creator","IAM","role","to","the","directly","preceding","identity",",","with","first","account","from","the","list","granting","this","role","to","the","originating","account","(","templated",")",".",":","param","deferrable",":","Run","operator","in","the","deferrable","mode",".",":","param","expected_terminal_state",":","The","expected","final","status","of","the","operator","on","which","the","corresponding","Airflow","task","succeeds",".","When","not","specified",",","it","will","be","determined","by","the","hook",".",":","param","append_job_name",":","True","if","unique","suffix","has","to","be","appended","to","job","name","."]
code: def execute(self, context: Context):
      if self.append_job_name:
          self._append_uuid_to_job_name()
  
      def set_current_job(current_job):
          self.job = current_job
          DataflowJobLink.persist(
              self,
              context,
              self.project_id,
              self.location,
              self.job.get("id"),
          )
  
      self.job = self.hook.start_flex_template(
          body=self.body,
          location=self.location,
          project_id=self.project_id,
          on_new_job_callback=set_current_job,
      )
  
      job_id = self.job.get("id")
      if job_id is None:
          raise AirflowException(
              "While reading job object after template execution error occurred. Job object has no id."
          )
  
      if not self.deferrable:
          return self.job
  
      self.defer(
          trigger=TemplateJobStartTrigger(
              project_id=self.project_id,
              job_id=job_id,
              location=self.location,
              gcp_conn_id=self.gcp_conn_id,
              impersonation_chain=self.impersonation_chain,
              cancel_timeout=self.cancel_timeout,
          ),
          method_name="execute_complete",
      )
  
imports: from __future__ import annotations
  import copy
  import re
  import uuid
  import warnings
  from contextlib import ExitStack
  from enum import Enum
  from functools import cached_property
  from typing import TYPE_CHECKING, Any, Sequence
  from airflow.configuration import conf
  from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
  from airflow.providers.apache.beam.hooks.beam import BeamHook, BeamRunnerType
  from airflow.providers.google.cloud.hooks.dataflow import DEFAULT_DATAFLOW_LOCATION, DataflowHook, process_line_and_extract_dataflow_job_id_callback
  from airflow.providers.google.cloud.hooks.gcs import GCSHook
  from airflow.providers.google.cloud.links.dataflow import DataflowJobLink
  from airflow.providers.google.cloud.operators.cloud_base import GoogleCloudBaseOperator
  from airflow.providers.google.cloud.triggers.dataflow import TemplateJobStartTrigger
  from airflow.version import version
label_desc: Use image node_id 4 for calling the DataflowStartFlexTemplateOperator obj's underlying member method code with example usage: obj.execute(context) and returns: self