コード例 #1
0
def _make_wait_call_state(previous_attempt_number,
                          delay_since_first_attempt,
                          last_result=None):
    required_parameter_unset = (previous_attempt_number is _unset
                                or delay_since_first_attempt is _unset)
    if required_parameter_unset:
        missing = []
        if previous_attempt_number is _unset:
            missing.append('previous_attempt_number')
        if delay_since_first_attempt is _unset:
            missing.append('delay_since_first_attempt')
        missing_str = ', '.join(repr(s) for s in missing)
        raise TypeError('wait func missing parameters: ' + missing_str)

    from tenacity import RetryCallState
    retry_state = RetryCallState(None, None, (), {})
    retry_state.attempt_number = previous_attempt_number
    if last_result is not None:
        retry_state.outcome = last_result
    else:
        retry_state.set_result(None)
    # Ensure outcome_timestamp - start_time is *exactly* equal to the delay to
    # avoid complexity in test code.
    retry_state.start_time = Fraction(retry_state.start_time)
    retry_state.outcome_timestamp = (retry_state.start_time +
                                     Fraction(delay_since_first_attempt))
    assert retry_state.seconds_since_start == delay_since_first_attempt
    return retry_state
コード例 #2
0
def _make_wait_call_state(previous_attempt_number,
                          delay_since_first_attempt,
                          last_result=None):
    required_parameter_unset = (previous_attempt_number is _unset
                                or delay_since_first_attempt is _unset)
    if required_parameter_unset:
        missing = []
        if previous_attempt_number is _unset:
            missing.append('previous_attempt_number')
        if delay_since_first_attempt is _unset:
            missing.append('delay_since_first_attempt')
        missing_str = ', '.join(repr(s) for s in missing)
        raise TypeError('wait func missing parameters: ' + missing_str)

    from tenacity import RetryCallState
    call_state = RetryCallState(None, (), {})
    call_state.attempt_number = previous_attempt_number
    call_state.outcome_timestamp = (call_state.start_time +
                                    delay_since_first_attempt)
    call_state.outcome = last_result
    return call_state