(domain, max_wait, delay_rather_than_reject, datadog_metric)
return acquired
Attempt to acquire permission from the rate limiter waiting up to 15 seconds.

    When delay_rather_than_reject is False

        If it's acquired, report throttle_method:delay and duration:<bucketed duration>;
        otherwise report throttle_method:reject and duration:delayed_reject or quick_reject,
        depending on whether the rate limiter bothered to wait or could tell there was no chance.

    When delay_rather_than_reject is True

        If it's acquired, report throttle_method:delay and duration:<bucketed duration> (as before);
        otherwise report throttle_method:delay and duration:delay_rather_than_reject

    Returns whether the permission was eventually acquired (with no variation on delay_rather_than_reject).
Attempt to acquire permission from the rate limiter waiting up to 15 seconds.
Attempt to acquire permission from the rate limiter waiting up to 15 seconds .
def _delay_and_report_rate_limit_submission(domain, max_wait, delay_rather_than_reject, datadog_metric):
    """
    Attempt to acquire permission from the rate limiter waiting up to 15 seconds.

    When delay_rather_than_reject is False

        If it's acquired, report throttle_method:delay and duration:<bucketed duration>;
        otherwise report throttle_method:reject and duration:delayed_reject or quick_reject,
        depending on whether the rate limiter bothered to wait or could tell there was no chance.

    When delay_rather_than_reject is True

        If it's acquired, report throttle_method:delay and duration:<bucketed duration> (as before);
        otherwise report throttle_method:delay and duration:delay_rather_than_reject

    Returns whether the permission was eventually acquired (with no variation on delay_rather_than_reject).
    """
    with TimingContext() as timer:
        acquired = submission_rate_limiter.wait(domain, timeout=max_wait)
    if acquired:
        duration_tag = bucket_value(timer.duration, [.5, 1, 5, 10, 15], unit='s')
    elif delay_rather_than_reject:
        if timer.duration < max_wait:
            time.sleep(max_wait - timer.duration)
        duration_tag = 'delay_rather_than_reject'
    elif timer.duration < max_wait:
        duration_tag = 'quick_reject'
    else:
        duration_tag = 'delayed_reject'
    metrics_counter(datadog_metric, tags={
        'domain': domain,
        'duration': duration_tag,
        'throttle_method': "delay" if acquired or delay_rather_than_reject else "reject"
    })
    return acquired
def _delay_and_report_rate_limit_submission ( domain , max_wait , delay_rather_than_reject , datadog_metric ) : with TimingContext ( ) as timer : acquired = submission_rate_limiter . wait ( domain , timeout = max_wait ) if acquired : duration_tag = bucket_value ( timer . duration , [ .5 , 1 , 5 , 10 , 15 ] , unit = 's' ) elif delay_rather_than_reject : if timer . duration < max_wait : time . sleep ( max_wait - timer . duration ) duration_tag = 'delay_rather_than_reject' elif timer . duration < max_wait : duration_tag = 'quick_reject' else : duration_tag = 'delayed_reject' metrics_counter ( datadog_metric , tags = { 'domain' : domain , 'duration' : duration_tag , 'throttle_method' : "delay" if acquired or delay_rather_than_reject else "reject" } ) return acquired