Esempio n. 1
0
 def __read_papi_v1_operation_metadata(
         operation_id: str,
         genomics_v1_client: Resource) -> Mapping[str, Any]:
     """Reads the operations metadata for a pipelines API v1 job ID. Returns a python dict"""
     logger.info(
         f'Reading PAPI v1 operation metadata for {operation_id}...')
     result = genomics_v1_client.operations().get(
         name=operation_id).execute()
     return result
Esempio n. 2
0
def _throw_if_error(client: discovery.Resource, project_id: str,
                    operation_id: str, operation_type: str) -> None:
    operation = client.operations().get(project=project_id,
                                        operation=operation_id).execute()

    if 'error' in operation:
        errors = operation['error'].get('errors', [])
        error_messages = [
            'code: {}\n message: {}'.format(error['code'], error['message'])
            for error in errors
        ]
        raise RuntimeError('Backup {} operation finished with '
                           '{} errors:\n{}'.format(operation_type,
                                                   str(len(errors)),
                                                   '\n'.join(error_messages)))
Esempio n. 3
0
def _await_operation(client: discovery.Resource, project_id: str,
                     operation_id: str) -> None:
    done = False
    while True:
        if done:
            break

        operation = client.operations().get(project=project_id,
                                            operation=operation_id).execute()
        current_status = operation['status']

        if current_status in {'PENDING', 'RUNNING', 'UNKNOWN'}:
            time.sleep(_SECONDS_BETWEEN_OPERATION_STATUS_CHECKS)
        elif current_status == 'DONE':
            done = True
        else:
            raise RuntimeError(
                'Unrecognized operation status: {}'.format(current_status))