4
4
import time
5
5
import requests
6
6
import argparse
7
+ from tenacity import retry , wait_fixed , stop_after_delay
7
8
from azure .storage .blob import BlobServiceClient
8
9
from azure .identity import DefaultAzureCredential
9
10
from azure .mgmt .web import WebSiteManagementClient
10
11
from azure .mgmt .storage import StorageManagementClient
11
12
logging .getLogger ('azure' ).setLevel (logging .WARNING )
12
13
13
14
def call_search_api (search_service , search_api_version , resource_type , resource_name , method , credential , body = None ):
14
-
15
15
# get the token
16
16
token = credential .get_token ("https://search.azure.com/.default" ).token
17
17
@@ -40,6 +40,13 @@ def call_search_api(search_service, search_api_version, resource_type, resource_
40
40
logging .error (f"Error when calling search API { method } { resource_type } { resource_name } . Error: { error_message } " )
41
41
return response
42
42
43
+ @retry (stop = stop_after_delay (10 * 60 ), wait = wait_fixed (60 ), before_sleep = lambda _ : logging .info ('Will attempt again in a minute as the function may not yet be available for use. Appreciate your patience....' ))
44
+ def get_function_key (subscription_id , resource_group , function_app_name ):
45
+ credential = DefaultAzureCredential ()
46
+ web_mgmt_client = WebSiteManagementClient (credential , subscription_id )
47
+ keys = web_mgmt_client .web_apps .list_function_keys (resource_group , function_app_name , 'document_chunkings' )
48
+ function_ley = keys .additional_properties ["default" ]
49
+
43
50
def execute_setup (subscription_id , resource_group , function_app_name ):
44
51
45
52
logging .info (f"Getting function app { function_app_name } properties." )
@@ -56,9 +63,8 @@ def execute_setup(subscription_id, resource_group, function_app_name):
56
63
storage_container_chunks = function_app_settings .properties ["STORAGE_CONTAINER_CHUNKS" ]
57
64
storage_account_name = function_app_settings .properties ["STORAGE_ACCOUNT_NAME" ]
58
65
59
- logging .info (f"Getting function app { function_app_name } key." )
60
- keys = web_mgmt_client .web_apps .list_function_keys (resource_group , function_app_name , 'document_chunking' )
61
- function_ley = keys .additional_properties ["default" ]
66
+ logging .info (f"Getting function app { function_app_name } key." )
67
+ function_ley = get_function_key (subscription_id , resource_group , function_app_name )
62
68
63
69
logging .info (f"Getting { function_app_name } storage connection string." )
64
70
storage_client = StorageManagementClient (credential , subscription_id )
0 commit comments