示例#1
0
def raise_if_match_wf_in_error_or_initial(obj, eng):
    """Raise if a matching wf is in ERROR or INITIAL state in the HoldingPen.

    Uses a custom configuration of the ``inspire-matcher`` to find duplicates
    of the current workflow object in the Holding Pen not in the
    that are in ERROR or INITIAL state.

    If any match is found, it sets ``error_workflows_matched`` in
    ``extra_data`` to the list of ids that matched and raise an error.

    Arguments:
        obj: a workflow object.
        eng: a workflow engine.

    Returns:
        None

    """
    def _filter(base_record, match_result):
        return get_value(match_result,
                         '_source._workflow.status') in ('ERROR', 'INITIAL')

    matched_ids = pending_in_holding_pen(obj, _filter)
    if bool(matched_ids):
        obj.extra_data['error_workflows_matched'] = matched_ids
        raise WorkflowsError(
            'Cannot continue processing. Found workflows in ERROR or INITIAL '
            'state: {}'.format(matched_ids))
示例#2
0
def create_error(response):
    """Raises exception with message from data returned by the server in response object"""
    if response.status_code == 502:
        raise BadGatewayError()

    try:
        error_msg = response.json()
    except JSONDecodeError:
        error_msg = response.text
    raise WorkflowsError("Error from inspirehep [{code}]: {message}".format(
        code=response.status_code, message=error_msg))
示例#3
0
def create_error(response):
    """Raises exception with message from data returned by the server in response object"""
    try:
        error_msg = response.json()
    except JSONDecodeError:
        error_msg = response.text
    raise WorkflowsError(
        "Response code from Inspirehep is {code}."
        " This is wrong! Message from the server: {message}".format(
            code=response.status_code, message=error_msg
        )
    )
示例#4
0
def raise_if_match_workflow(obj, eng):
    """Raise if a matching wf is not in completed state in the HoldingPen.

    Arguments:
        obj: a workflow object.
        eng: a workflow engine.

    Returns:
        None

    """
    matched_ids = set_wf_not_completed_ids_to_wf(obj,
                                                 skip_blocked=True,
                                                 skip_halted=True)
    if bool(matched_ids):
        raise WorkflowsError('Cannot continue processing workflow {wf_id}.'
                             'Found not-completed workflows in holdingpen '
                             ': {blocking_ids}'.format(
                                 wf_id=obj.id, blocking_ids=matched_ids))
示例#5
0
def increase_restart_count_or_error(obj, eng):
    """Increase the `restart-count` of the current workflow.

    If `restart-count` contains a value greater than WORKFLOWS_RESTART_LIMIT it
    throws a WorkflowError. If `restart-count` is not in
    `extra_data.persistent_data.marks` the increment is skipped.
    """
    try:
        count = obj.extra_data['source_data']['persistent_data']['marks'][
            'restart-count']
    except KeyError:
        count = None

    if count is None:
        return
    if count < current_app.config.get('WORKFLOWS_RESTART_LIMIT'):
        obj.extra_data['source_data']['persistent_data']['marks'][
            'restart-count'] += 1
        save_workflow(obj, eng)
    else:
        raise WorkflowsError('Workflow restarted too many times')
示例#6
0
 def _error_workflow(obj, eng):
     obj.log.error(message)
     obj.extra_data['_error_msg'] = message
     obj.status = ObjectStatus.ERROR
     raise WorkflowsError(message)