retry logic on top of package object method call in python

175 Views Asked by At

I am using the azure-keyvault python package to authenticate with azure. I am trying to add retry logic to the api call client.get_secret(secretName) shown below.

import os
from azure.keyvault.secrets import SecretClient
from azure.identity import DefaultAzureCredential

keyVaultName = os.environ["KEY_VAULT_NAME"]
KVUri = f"https://{keyVaultName}.vault.azure.net"

credential = DefaultAzureCredential()
client = SecretClient(vault_url=KVUri, credential=credential)

secretName = input("Input a name for your secret > ")
secretValue = input("Input a value for your secret > ")

print(f"Creating a secret in {keyVaultName} called '{secretName}' with the value '{secretValue}' ...")

client.set_secret(secretName, secretValue)

print(" done.")

print(f"Retrieving your secret from {keyVaultName}.")

retrieved_secret = client.get_secret(secretName)

I want to use the retrying (https://pypi.org/project/retrying/) python package as below example:

@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000)
def wait_exponential_1000():
    print "Wait 2^x * 1000 milliseconds between each retry, up to 10 seconds, then 10 seconds afterwards"

and my question is how can I add @retry(...) to a method call like client.get_secret(secretName), where client is an object of an imported package?

Thank you

0

There are 0 best solutions below