
    *
                         S 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\R                  5      rg)z The BigQuery CLI cancel command.    )Optional)flagsN)
client_job)utils)bigquery_command)bq_cached_client)bq_id_utilsc                   l   ^  \ rS rSrSrSrS\S\R                  4U 4S jjr	SS\S\
\   4S	 jjrS
rU =r$ )Cancel   z5Attempt to cancel the specified job if it is running.zcancel [--nosync] [<job_id>]namefvc                 N   > [         [        U ]  X5        U R                  U5        g )N)superr   __init___ProcessCommandRc)selfr   r   	__class__s      &platform/bq/frontend/command_cancel.pyr   Cancel.__init__   s     	&$ *2    job_idreturnc           	         [         R                  R                  5       n[        [        R
                  " UU[        R                  R                  S95      n[        R                  " UUS   US   S9n[        R                  " U[        R                  R                  R                   " S0 US   D6SS9  US   nUS	   S
:X  a4  SU;   a!  SUS   ;   a  US   S   S:X  a  [#        S5        g[#        S5         g[#        S5        g)a  Request a cancel and waits for the job to be cancelled.

Requests a cancel and then either:
a) waits until the job is done if the sync flag is set [default], or
b) returns immediately if the sync flag is not set.
Not all job types support a cancel, an error is returned if it cannot be
cancelled. Even for jobs that support a cancel, success is not guaranteed,
the job may have completed by the time the cancel request is noticed, or
the job may be in a stage where it cannot be cancelled.

Examples:
  bq cancel job_id  # Requests a cancel and waits until the job is done.
  bq --nosync cancel job_id  # Requests a cancel and returns immediately.

Arguments:
  job_id: Job ID to cancel.
)id_fallbacks
identifierdefault_locationjobIdlocation)bqclientr   r   jobReferenceshow)custom_formatstatusstateDONEerrorResultreasonstoppedz$Job has been cancelled successfully.z+Job completed before it could be cancelled.zJob cancel has been requested.r    )r   ClientGetdictbq_client_utilsGetJobReferencebq_flagsLOCATIONvaluer   	CancelJobfrontend_utilsPrintObjectInfor	   ApiClientHelperJobReferenceCreateprint)r   r   clientjob_reference_dictjobr$   s         r   RunWithArgsCancel.RunWithArgs   s   & $$((*F''%..44	
 

!'*#J/C
 ""##0077N#n:MN
 ]Fg& 
6
!&//]#H-:45
  	;<  ,-r   r*   ) )__name__
__module____qualname____firstlineno____doc__usagestrr   
FlagValuesr   r   intr=   __static_attributes____classcell__)r   s   @r   r   r      s@    =
,%3 E$4$4 1 1Xc] 1 1r   r   )rD   typingr   abslr   r0   clientsr   r   r.   frontendr   r   r4   r	   BigqueryCmdr   r*   r   r   <module>rP      s6    &     , % % , :)) :r   