File: client_user_configs_async.py

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (51 lines) | stat: -rw-r--r-- 2,565 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from azure.cosmos.aio import CosmosClient
import config
import asyncio

HOST = config.settings['host']
MASTER_KEY = config.settings['master_key']

# ----------------------------------------------------------------------------------------------------------
# Prerequisites -
#
# 1. An Azure Cosmos account -
#    https://azure.microsoft.com/documentation/articles/documentdb-create-account/
#
# 2. Microsoft Azure Cosmos PyPi package -
#    https://pypi.python.org/pypi/azure-cosmos/
# ----------------------------------------------------------------------------------------------------------
# Sample - demonstrates how to pass in values for the connection policy retry options.
#
# 1. retry_total is the total number of retries to allow. Takes precedence over other counts.
#    Pass in retry_total=0 if you do not want to retry on requests. Default value is 10
#
# 2. retry_connect option determines how many connection-related errors to retry on. Default value is 3
#
# 3. retry_read option determines how many times to retry on read errors. Default value is 3
#
# 4. retry_status determines how many times to retry on bad status codes. Default value is 3
#
# 5. retry_on_status_codes is a list of specific status codes to retry on. The default value is an empty list as the
#    SDK has its own retry logic already configured where this is option is taken care of.
#
# 6. retry_backoff_factor is a factor to calculate wait time between retry attempts. Defaults to .08 seconds
#
# 7. retry_backoff_max option determines the maximum back off time. Default value is 120 seconds (2 minutes)
#
# 8. retry_fixed_interval option determines the fixed retry interval in milliseconds.
#    The default value is None as the SDK has its own retry logic configured where this option is taken care of.
#
# Note:
# While these options can be configured, the SDK by default already has retry mechanisms and we recommend to use those.
# ----------------------------------------------------------------------------------------------------------

async def change_connection_retry_policy_configs():
    async with CosmosClient(url=HOST, credential=MASTER_KEY, retry_total=10, retry_connect=3,
                               retry_read=3, retry_status=3,
                               retry_on_status_codes=([]),
                               retry_backoff_factor=.08, retry_backoff_max=120, retry_fixed_interval=None) as client:
        print('Client initialized with custom retry options')


if __name__ == "__main__":
    asyncio.run(change_connection_retry_policy_configs())