def METHOD_NAME(
    func,
    logger=None,
    retry_classes=None,
    fail_classes=None,
    account_id=None,
    provider=None,
    backoff_delay=BACKOFF_DELAY,
):
    # Sharing the network_errs counter between invocations of callback by
    # placing it inside an array:
    # http://stackoverflow.com/questions/7935966/python-overwriting-variables-in-nested-functions
    occurrences = [0]
    def callback(e):
        is_transient = isinstance(e, TRANSIENT_NETWORK_ERRS)
        mysql_error = None
        log = logger or get_logger()
        if isinstance(e, _mysql_exceptions.OperationalError):
            mysql_error = e
        elif isinstance(e, StatementError) and isinstance(
            e.orig, _mysql_exceptions.OperationalError
        ):
            mysql_error = e.orig
        if mysql_error and mysql_error.args and isinstance(mysql_error.args[0], str):
            for msg in TRANSIENT_MYSQL_MESSAGES:
                if msg in mysql_error.args[0]:
                    is_transient = True
        if is_transient:
            occurrences[0] += 1
            if occurrences[0] < 20:
                return
        else:
            occurrences[0] = 1
        if account_id:
            try:
                with session_scope(account_id) as db_session:
                    account = db_session.query(Account).get(account_id)
                    sync_error = account.sync_error
                    if not sync_error or isinstance(sync_error, str):
                        account.update_sync_error(e)
                        db_session.commit()
            except Exception:
                log.error(
                    "Error saving sync_error to account object",
                    account_id=account_id,
                    **create_error_log_context(sys.exc_info())
                )
        log_uncaught_errors(
            logger, account_id=account_id, provider=provider, occurrences=occurrences[0]
        )
    return retry(
        func,
        exc_callback=callback,
        retry_classes=retry_classes,
        fail_classes=fail_classes,
        backoff_delay=backoff_delay,
    )()