
                             S r SSKrSSKJr  SSKJr  SSKJr  SSKrSSKJ	r	  SSKJ
r  SSKJr  SS	KJr  SSKJ
r  SS
K
Jr  SSK
Jr   " S S\R$                  5      rg)zThe BigQuery CLI wait command.    N)Optional)app)flags)
client_job)utils)bigquery_command)bq_cached_client)bq_error)bq_id_utilsc                   |   ^  \ rS rSrSrS\S\R                  4U 4S jjrS\	R                  4S\\   4S jjrS	rU =r$ )
Wait   zwait [<job_id>] [<secs>]namefvc                    > [         [        U ]  X5        [        R                  " SSSUS9  [        R
                  " SSSUS9  U R                  U5        g )Nfail_on_errorTzsWhen done waiting for the job, exit the process with an error if the job is still running, or ended with a failure.)flag_valueswait_for_statusDONEz;Wait for the job to have a certain status. Default is DONE.)superr   __init__r   DEFINE_booleanDEFINE_string_ProcessCommandRc)selfr   r   	__class__s      $platform/bq/frontend/command_wait.pyr   Wait.__init__   s[    	$t(		@ 
E	 	2     returnc           	          [         R                  " U5      n[
        R                  R                  5       nU(       dZ  [        R                  " USS/S9n[        U5      S:w  a#  [        R                  " S[        U5      4-  5      eUR                  5       nO.[         R                  " UU[        R                   R"                  S9n [        R$                  " UUUU R&                  S9n[(        R*                  " U[,        R.                  R0                  R2                  " S0 US	   D6S
S9  U R4                  (       a  [         R6                  " U5      (       a  S$ S$ ! [         a    [        R                  " SU< 35      ef = f! [8         a  n[;        5         [;        U5         SnAOSnAff = fU R4                  (       a  S$ S$ )a  Wait some number of seconds for a job to finish.

Poll job_id until either (1) the job is DONE or (2) the
specified number of seconds have elapsed. Waits forever
if unspecified. If no job_id is specified, and there is
only one running job, we poll that job.

Examples:
  bq wait # Waits forever for the currently running job.
  bq wait job_id  # Waits forever
  bq wait job_id 100  # Waits 100 seconds
  bq wait job_id 0  # Polls if a job is done, then returns immediately.
  # These may exit with a non-zero status code to indicate "failure":
  bq wait --fail_on_error job_id  # Succeeds if job succeeds.
  bq wait --fail_on_error job_id 100  # Succeeds if job succeeds in 100 sec.

Arguments:
  job_id: Job ID to wait on.
  secs: Number of seconds to wait (must be >= 0).
zInvalid wait time: PENDINGRUNNING)bqclientstate_filter   z)No job_id provided, found %d running jobs)id_fallbacks
identifierdefault_location)r%   job_referencewaitstatusjobReferenceshow)custom_formatr   N )bq_client_utilsNormalizeWait
ValueErrorr   
UsageErrorr	   ClientGetr   ListJobRefslenr
   BigqueryErrorpopGetJobReferencebq_flagsLOCATIONvalueWaitJobr   frontend_utilsPrintObjectInfor   ApiClientHelperJobReferenceCreater   IsFailedJobStopIterationprint)r   job_idsecsclientrunning_jobsr+   jobes           r   RunWithArgsWait.RunWithArgs,   s   ,>**40d $$((*F++I(>l 
\	a	$$73|;L:NN
 	
 #&&(m%55#,,22m
%%%	c $$


%
%
2
2
9
9 N#  $$)D)DS)I)IQPqPC  >NNd<==>D  gAhh ""1))s*   E BF  F  %E= 
F)
F$$F)r1   )__name__
__module____qualname____firstlineno__usagestrr   
FlagValuesr   sysmaxsizer   intrO   __static_attributes____classcell__)r   s   @r   r   r      sA    
(%3 E$4$4 "  " >* >* >*r   r   )__doc__rX   typingr   abslr   r   r=   clientsr   r   r2   frontendr   r	   rA   r
   r   BigqueryCmdr   r1   r   r   <module>rc      sA    $ 
      , % % ,  R*'' R*r   