class_docstr: Trigger a Jenkins Job and monitor its execution.
  
  This operator depend on the python-jenkins library version >= 0.4.15 to
  communicate with the Jenkins server. You'll also need to configure a Jenkins
  connection in the connections screen.
  
  :param jenkins_connection_id: The jenkins connection to use for this job
  :param job_name: The name of the job to trigger
  :param parameters: The parameters block provided to jenkins for use in
      the API call when triggering a build. (templated)
  :param sleep_time: How long will the operator sleep between each status
      request for the job (min 1, default 10)
  :param max_try_before_job_appears: The maximum number of requests to make
      while waiting for the job to appears on jenkins server (default 10)
  :param allowed_jenkins_states: Iterable of allowed result jenkins states, default is ``['SUCCESS']``
class_docstr_tok: ["Trigger","a","Jenkins","Job","and","monitor","its","execution",".","This","operator","depend","on","the","python-jenkins","library","version",">","=","0.4.15","to","communicate","with","the","Jenkins","server",".","You","'ll","also","need","to","configure","a","Jenkins","connection","in","the","connections","screen",".",":","param","jenkins_connection_id",":","The","jenkins","connection","to","use","for","this","job",":","param","job_name",":","The","name","of","the","job","to","trigger",":","param","parameters",":","The","parameters","block","provided","to","jenkins","for","use","in","the","API","call","when","triggering","a","build",".","(","templated",")",":","param","sleep_time",":","How","long","will","the","operator","sleep","between","each","status","request","for","the","job","(","min","1",",","default","10",")",":","param","max_try_before_job_appears",":","The","maximum","number","of","requests","to","make","while","waiting","for","the","job","to","appears","on","jenkins","server","(","default","10",")",":","param","allowed_jenkins_states",":","Iterable","of","allowed","result","jenkins","states",",","default","is","``","[","'SUCCESS","'","]","``"]
docstr: Poll the jenkins queue until the job is executed.
  
  When we trigger a job through an API call, the job is first put in the
  queue without having a build number assigned. We have to wait until the
  job exits the queue to know its build number.
  
  To do so, we add ``/api/json`` (or ``/api/xml``) to the location
  returned by the ``build_job`` call, and poll this file. When an
  ``executable`` block appears in the response, the job execution would
  have started, and the field ``number`` would contains the build number.
  
  :param location: Location to poll, returned in the header of the build_job call
  :param jenkins_server: The jenkins server to poll
  :return: The build_number corresponding to the triggered job
docstr_tok: ["Poll","the","jenkins","queue","until","the","job","is","executed",".","When","we","trigger","a","job","through","an","API","call",",","the","job","is","first","put","in","the","queue","without","having","a","build","number","assigned",".","We","have","to","wait","until","the","job","exits","the","queue","to","know","its","build","number",".","To","do","so",",","we","add","``","\/api\/json","``","(","or","``","\/api\/xml","``",")","to","the","location","returned","by","the","``","build_job","``","call",",","and","poll","this","file",".","When","an","``","executable","``","block","appears","in","the","response",",","the","job","execution","would","have","started",",","and","the","field","``","number","``","would","contains","the","build","number",".",":","param","location",":","Location","to","poll",",","returned","in","the","header","of","the","build_job","call",":","param","jenkins_server",":","The","jenkins","server","to","poll",":","return",":","The","build_number","corresponding","to","the","triggered","job"]
code: def poll_job_in_queue(
      self, location: str, jenkins_server: Jenkins
  ) -> int:
      """Poll the jenkins queue until the job is executed.
  
      When we trigger a job through an API call, the job is first put in the
      queue without having a build number assigned. We have to wait until the
      job exits the queue to know its build number.
  
      To do so, we add ``/api/json`` (or ``/api/xml``) to the location
      returned by the ``build_job`` call, and poll this file. When an
      ``executable`` block appears in the response, the job execution would
      have started, and the field ``number`` would contains the build number.
  
      :param location: Location to poll, returned in the header of the build_job call
      :param jenkins_server: The jenkins server to poll
      :return: The build_number corresponding to the triggered job
      """
      location += "/api/json"
      # TODO Use get_queue_info instead
      # once it will be available in python-jenkins (v > 0.4.15)
      self.log.info("Polling jenkins queue at the url %s", location)
      for attempt in range(self.max_try_before_job_appears):
          if attempt:
              time.sleep(self.sleep_time)
  
          try:
              location_answer = jenkins_request_with_headers(
                  jenkins_server, Request(method="POST", url=location)
              )
          # we don't want to fail the operator, this will continue to poll
          # until max_try_before_job_appears reached
          except (HTTPError, JenkinsException):
              self.log.warning(
                  "polling failed, retrying", exc_info=True
              )
          else:
              if location_answer is not None:
                  json_response = json.loads(location_answer["body"])
                  if (
                      "executable" in json_response
                      and json_response["executable"] is not None
                      and "number" in json_response["executable"]
                  ):
                      build_number = json_response["executable"][
                          "number"
                      ]
                      self.log.info(
                          "Job executed on Jenkins side with the build number %s",
                          build_number,
                      )
                      return build_number
      else:
          raise AirflowException(
              f"The job hasn't been executed after polling the queue "
              f"{self.max_try_before_job_appears} times"
          )
  
imports: from __future__ import annotations
  import ast
  import json
  import socket
  import time
  from functools import cached_property
  from typing import Any, Iterable, Mapping, Sequence, Union
  from urllib.error import HTTPError, URLError
  import jenkins
  from deprecated.classic import deprecated
  from jenkins import Jenkins, JenkinsException
  from requests import Request
  from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
  from airflow.models import BaseOperator
  from airflow.providers.jenkins.hooks.jenkins import JenkinsHook
label_desc: Use image node_id 3 for calling the JenkinsJobTriggerOperator obj's underlying member method code with example usage: obj.poll_job_in_queue(location, jenkins_server) and returns: build_number