Skip to content

Commit a71d3aa

Browse files
authored
Merge pull request #178516 from gavin-aguiar/gaaguiar/update_func_python_docs
Updated python function docs to include retry context examples
2 parents 0ea6d75 + a360c84 commit a71d3aa

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

articles/azure-functions/functions-reference-python.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ def main(req, context):
302302
'ctx_invocation_id': context.invocation_id,
303303
'ctx_trace_context_Traceparent': context.trace_context.Traceparent,
304304
'ctx_trace_context_Tracestate': context.trace_context.Tracestate,
305+
'ctx_retry_context_RetryCount': context.retry_context.retry_count,
306+
'ctx_retry_context_MaxRetryCount': context.retry_context.max_retry_count,
305307
})
306308
```
307309

@@ -370,6 +372,12 @@ Name of the function.
370372
`invocation_id`
371373
ID of the current function invocation.
372374

375+
`trace_context`
376+
Context for distributed tracing. Please refer to [`Trace Context`](https://www.w3.org/TR/trace-context/) for more information..
377+
378+
`retry_context`
379+
Context for retries to the function. Please refer to [`retry-policies`](./functions-bindings-errors.md#retry-policies-preview) for more information.
380+
373381
## Global variables
374382

375383
It is not guaranteed that the state of your app will be preserved for future executions. However, the Azure Functions runtime often reuses the same process for multiple executions of the same app. In order to cache the results of an expensive computation, declare it as a global variable.

includes/functions-bindings-errors-retries.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,23 @@ Here's the retry policy in the *function.json* file:
124124
}
125125
```
126126

127+
Here's a python sample to use retry context in a function:
128+
129+
```Python
130+
import azure.functions
131+
import logging
132+
133+
134+
def main(req: azure.functions.HttpRequest, context: azure.functions.Context) -> None:
135+
logging.log(f'Current retry count: {context.retry_context.retry_count}')
136+
137+
if context.retry_context.retry_count == context.retry_context.max_retry_count:
138+
logging.log(
139+
f"Max retries of {context.retry_context.max_retry_count} for "
140+
f"function {context.function_name} has been reached")
141+
142+
```
143+
127144
# [Java](#tab/java)
128145

129146
Here's the retry policy in the *function.json* file:
@@ -245,6 +262,23 @@ Here's the retry policy in the *function.json* file:
245262
}
246263
```
247264

265+
Here's a python sample to use retry context in a function:
266+
267+
```Python
268+
import azure.functions
269+
import logging
270+
271+
272+
def main(req: azure.functions.HttpRequest, context: azure.functions.Context) -> None:
273+
logging.log(f'Current retry count: {context.retry_context.retry_count}')
274+
275+
if context.retry_context.retry_count == context.retry_context.max_retry_count:
276+
logging.log(
277+
f"Max retries of {context.retry_context.max_retry_count} for "
278+
f"function {context.function_name} has been reached")
279+
280+
```
281+
248282
# [Java](#tab/java)
249283

250284
Here's the retry policy in the *function.json* file:

0 commit comments

Comments
 (0)