def CancelBatchJob(client, batch_job, max_poll_attempts=MAX_POLL_ATTEMPTS):
 batch_job_service = client.GetService('BatchJobService', 'v201607')
 batch_job['status'] = 'CANCELING'
 operation = {'operator': 'SET', 'operand': batch_job}
 batch_job_service.mutate([operation])
 poll_attempt = 0
 while ((poll_attempt in range(max_poll_attempts)) and (batch_job['status'] != 'CANCELED')):
  sleep_interval = ((30 * (2 ** poll_attempt)) + (random.randint(0, 10000) / 1000))
  print ('Batch Job not finished canceling, sleeping for %s seconds.' % sleep_interval)
  time.sleep(sleep_interval)
  batch_job = GetBatchJob(client, batch_job['id'])
  poll_attempt += 1
 if (batch_job['status'] == 'CANCELED'):
  print ('Batch Job with ID "%d" has been successfully canceled.' % batch_job['id'])
 else:
  print ('Batch Job with ID "%d" failed to cancel after polling %d times.' % (batch_job['id'], max_poll_attempts))

def CancelBatchJob ( client , batch_job , max_poll_attempts = MAX_POLL_ATTEMPTS ) : batch_job_service = client . GetService ( 'BatchJobService' , 'v201607' ) batch_job [ 'status' ] = 'CANCELING' operation = { 'operator' : 'SET' , 'operand' : batch_job } batch_job_service . mutate ( [ operation ] ) poll_attempt = 0 while ( ( poll_attempt in range ( max_poll_attempts ) ) and ( batch_job [ 'status' ] != 'CANCELED' ) ) : sleep_interval = ( ( 30 * ( 2 ** poll_attempt ) ) + ( random . randint ( 0 , 10000 ) / 1000 ) ) print ( 'Batch Job not finished canceling, sleeping for %s seconds.' % sleep_interval ) time . sleep ( sleep_interval ) batch_job = GetBatchJob ( client , batch_job [ 'id' ] ) poll_attempt += 1 if ( batch_job [ 'status' ] == 'CANCELED' ) : print ( 'Batch Job with ID "%d" has been successfully canceled.' % batch_job [ 'id' ] ) else : print ( 'Batch Job with ID "%d" failed to cancel after polling %d times.' % ( batch_job [ 'id' ] , max_poll_attempts ) )
cancels the given batchjob .