docstr: Figures out what to do with a QueryPack that has finished running.
  
  This method is Idempotent.
  
  Arguments:
      query_pack (QueryPack)
docstr_tok: ["Figures","out","what","to","do","with","a","QueryPack","that","has","finished","running",".","This","method","is","Idempotent",".","Arguments",":","query_pack","(","QueryPack",")"]
code: def _handle_finished_query(self, query_pack):
      """Figures out what to do with a QueryPack that has finished running.
  
      This method is Idempotent.
  
      Arguments:
          query_pack (QueryPack)
      """
      query_execution = query_pack.query_execution
      query_execution_id = query_pack.query_execution_id
  
      # If query pack is sent
      if self._query_pack_already_sent(query_pack):
          self._logger.debug("  Already sent to Kinesis.")
          return
  
      if not query_execution.is_succeeded():
          # uh o
          self._logger.error("ENCOUNTERED ERROR")
          self._logger.error(
              "QUERY FOR {} (Execution Id = {}) HAS FAILED".format(
                  query_pack.query_pack_configuration.name,
                  query_execution_id,
              )
          )
          self._logger.error(query_execution.status_description)
  
          self._kinesis.send_error_results(query_pack)
  
          self._mark_query_pack_sent(query_pack)
          self._mark_query_pack_error(query_pack)
          return
  
      result = query_pack.fetch_results()
  
      self._logger.debug("Query Completed:")
      self._logger.debug(
          "Execution Id: %s", result.query_execution.query_execution_id
      )
      self._logger.debug("Query: %s", result.query_execution.query)
      self._logger.debug(
          "Runtime: %d",
          result.query_execution.engine_execution_time_in_millis,
      )
      self._logger.debug(
          "Bytes: %d", result.query_execution.data_scanned_in_bytes
      )
      self._logger.debug("Status: %s", result.query_execution.status)
      self._logger.debug(
          "Reason: %s", result.query_execution.status_description
      )
  
      self._kinesis.send_query_results(query_pack)
  
      self._mark_query_pack_sent(query_pack)
  
file_path: streamalert/streamalert/scheduled_queries/command/processor.py
imports: from logging import Logger
  from streamalert.scheduled_queries.query_packs.manager import QueryPacksManager
  from streamalert.scheduled_queries.state.state_manager import StateManager
  from streamalert.scheduled_queries.streamalert.kinesis import KinesisClient
label_desc: Use image node_id 3 for calling the CommandProcessor obj's underlying member method code with example usage: obj._handle_finished_query(query_pack) without return types