def wait_for_purge()

in src/lambda.d/nexus3-purge/index.py [0:0]


def wait_for_purge(args, timeout_seconds):

  end_time = time.time() + timeout_seconds
  error = None

  while time.time() < end_time:
    try:
      # the output is surrounded with '', so we unquote
      output = kubectl(args).decode('utf-8')[1:-1]
      if output:
        pass
    except Exception as e:
      error = str(e)
      # also a recoverable error
      if 'NotFound' in error:
          return 'Resource is purged'
      elif b'i/o timeout' in error:
          logger.warn(f"Got connection error '{error}' when watching resource, ignore it")
          return 'Cluster might be purged'
      else:
          raise
    time.sleep(10)

  raise RuntimeError(f'Timeout waiting for output from kubectl command: {args} (last_error={error})')