8
8
import os .path
9
9
import pathlib
10
10
import sys
11
+ import time
12
+ from datetime import timedelta
11
13
from os import PathLike , fspath
12
14
from typing import Optional , Dict
13
15
16
+ from google .protobuf .duration_pb2 import Duration
17
+
14
18
from . import protos , functions
19
+ from .bindings .retrycontext import RetryPolicy
15
20
from .constants import MODULE_NOT_FOUND_TS_URL , SCRIPT_FILE_NAME , \
16
- PYTHON_LANGUAGE_RUNTIME
21
+ PYTHON_LANGUAGE_RUNTIME , RETRY_POLICY
17
22
from .utils .wrappers import attach_message_to_exception
18
23
19
24
_AZURE_NAMESPACE = '__app__'
@@ -45,6 +50,12 @@ def install() -> None:
45
50
sys .modules [_AZURE_NAMESPACE ] = ns_pkg
46
51
47
52
53
+ def convert_to_seconds (timestr : str ):
54
+ x = time .strptime (timestr , '%H:%M:%S' )
55
+ return int (timedelta (hours = x .tm_hour , minutes = x .tm_min ,
56
+ seconds = x .tm_sec ).total_seconds ())
57
+
58
+
48
59
def uninstall () -> None :
49
60
pass
50
61
@@ -60,6 +71,39 @@ def build_binding_protos(indexed_function) -> Dict:
60
71
return binding_protos
61
72
62
73
74
+ def build_retry_protos (indexed_function ) -> Dict :
75
+ retry = indexed_function .get_settings_dict (RETRY_POLICY )
76
+ if not retry :
77
+ return None
78
+
79
+ strategy = retry .get (RetryPolicy .STRATEGY .value )
80
+ if strategy == "fixed_delay" :
81
+ delay_interval = Duration (
82
+ seconds = convert_to_seconds (
83
+ retry .get (RetryPolicy .DELAY_INTERVAL .value )))
84
+ retry_protos = protos .RpcRetryOptions (
85
+ max_retry_count = int (retry .get (RetryPolicy .MAX_RETRY_COUNT .value )),
86
+ retry_strategy = retry .get (RetryPolicy .STRATEGY .value ),
87
+ delay_interval = delay_interval ,
88
+ )
89
+ else :
90
+ minimum_interval = Duration (
91
+ seconds = convert_to_seconds (
92
+ retry .get (RetryPolicy .MINIMUM_INTERVAL .value )))
93
+ maximum_interval = Duration (
94
+ seconds = convert_to_seconds (
95
+ retry .get (RetryPolicy .MAXIMUM_INTERVAL .value )))
96
+
97
+ retry_protos = protos .RpcRetryOptions (
98
+ max_retry_count = int (retry .get (RetryPolicy .MAX_RETRY_COUNT .value )),
99
+ retry_strategy = retry .get (RetryPolicy .STRATEGY .value ),
100
+ minimum_interval = minimum_interval ,
101
+ maximum_interval = maximum_interval
102
+ )
103
+
104
+ return retry_protos
105
+
106
+
63
107
def process_indexed_function (functions_registry : functions .Registry ,
64
108
indexed_functions ):
65
109
fx_metadata_results = []
@@ -68,6 +112,7 @@ def process_indexed_function(functions_registry: functions.Registry,
68
112
function = indexed_function )
69
113
70
114
binding_protos = build_binding_protos (indexed_function )
115
+ retry_protos = build_retry_protos (indexed_function )
71
116
72
117
function_metadata = protos .RpcFunctionMetadata (
73
118
name = function_info .name ,
@@ -80,6 +125,7 @@ def process_indexed_function(functions_registry: functions.Registry,
80
125
language = PYTHON_LANGUAGE_RUNTIME ,
81
126
bindings = binding_protos ,
82
127
raw_bindings = indexed_function .get_raw_bindings (),
128
+ retry_options = retry_protos ,
83
129
properties = {"worker_indexed" : "True" })
84
130
85
131
fx_metadata_results .append (function_metadata )
0 commit comments