RetryConfig Reference

class pyqldb.config.retry_config.RetryConfig(retry_limit=4, base=10, custom_backoff=None)[source]

Retry and Backoff Config for QldbDriver

Parameters
  • retry_limit (int) – The number of automatic retries for statement executions using pyqldb.driver.qldb_driver.QldbDriver.execute_lambda() when an OCC conflict or retriable exception occurs. This value must not be negative.

  • base (int) – The base number of milliseconds to use in the exponential backoff for operation retries. Defaults to 10 ms.

  • custom_backoff (function) – A custom function that accepts a retry count, error, transaction id and returns the amount of time to delay in milliseconds. If the result is a non-zero negative value the backoff will be considered to be zero. The base option will be ignored if this option is supplied.

Raises

ValueError – When base or retry_limit are negative.

property base

The base number of milliseconds to use in the exponential backoff for operation retries. Defaults to 10 ms.

property custom_backoff

A custom function that accepts a retry count, error, transaction id and returns the amount of time to delay in milliseconds. If the result is a non-zero negative value the backoff will be considered to be zero and will result in no delay. The base option will be ignored if this option is supplied.

property retry_limit

The number of automatic retries for statement executions using pyqldb.driver.qldb_driver.QldbDriver.execute_lambda() when an OCC conflict or retriable exception occurs. This value must not be negative.

Usage

from pyqldb.config.retry_config import RetryConfig
from pyqldb.driver.qldb_driver import QldbDriver

# Configuring Retry limit to 2
retry_config = RetryConfig(retry_limit=2)
qldb_driver = QldbDriver("test-ledger", retry_config=retry_config)

# Configuring a custom back off which increases delay by 1s for each attempt.

def custom_backoff(retry_attempt, error, transaction_id):
    return 1000 * retry_attempt

retry_config_custom_backoff = RetryConfig(retry_limit=2, custom_backoff=custom_backoff)
qldb_driver = QldbDriver("test-ledger", retry_config=retry_config_custom_backoff)