I am facing an issue to run the below code. I directly ran the code from the
Microsoft official documentation
Code:
from azure.functions import FunctionApp, TimerRequest, Context, AuthLevel
import logging
app = FunctionApp(http_auth_level=AuthLevel.ANONYMOUS)
@app.timer_trigger(schedule="*/1 * * * * *", arg_name="mytimer",
run_on_startup=False,
use_monitor=False)
@app.retry(strategy="fixed_delay", max_retry_count="3",
delay_interval="00:00:01")
def mytimer(mytimer: TimerRequest, context: Context) -> None:
logging.info(f'Current retry count: {context.retry_context.retry_count}')
if context.retry_context.retry_count == \
context.retry_context.max_retry_count:
logging.info(
f"Max retries of {context.retry_context.max_retry_count} for "
f"function {context.function_name} has been reached")
else:
raise Exception("This is a retryable exception")
I am getting this error
Received WorkerMetadataRequest, request ID b7bfaf90-17e3-4983-b4a5-1ce251db2312, directory: /src/components/test
[2024-06-05T03:09:22.466Z] Worker failed to index functions
[2024-06-05T03:09:22.466Z] Result: Failure
[2024-06-05T03:09:22.466Z] Exception: AttributeError: 'FunctionApp' object has no attribute 'retry'
[2024-06-05T03:09:22.466Z] Stack: File "/usr/lib/azure-functions-core-tools-4/workers/python/3.10/LINUX/X64/azure_functions_worker/dispatcher.py", line 338, in handle_functions_metadata_request
[2024-06-05T03:09:22.466Z] fx_metadata_results = self.index_functions(function_path)
[2024-06-05T03:09:22.466Z] File "/usr/lib/azure-functions-core-tools-4/workers/python/3.10/LINUX/X64/azure_functions_worker/dispatcher.py", line 607, in index_functions
[2024-06-05T03:09:22.466Z] indexed_functions = loader.index_function_app(function_path)
[2024-06-05T03:09:22.467Z] File "/usr/lib/azure-functions-core-tools-4/workers/python/3.10/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 44, in call
[2024-06-05T03:09:22.467Z] return func(*args, **kwargs)
[2024-06-05T03:09:22.467Z] File "/usr/lib/azure-functions-core-tools-4/workers/python/3.10/LINUX/X64/azure_functions_worker/loader.py", line 151, in index_function_app
[2024-06-05T03:09:22.467Z] imported_module = importlib.import_module(module_name)
[2024-06-05T03:09:22.467Z] File "/usr/local/lib/python3.10/importlib/_init_.py", line 126, in import_module
[2024-06-05T03:09:22.467Z] return _bootstrap._gcd_import(name[level:], package, level)
[2024-06-05T03:09:22.467Z] File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
[2024-06-05T03:09:22.468Z] File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
[2024-06-05T03:09:22.468Z] File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
[2024-06-05T03:09:22.468Z] File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
[2024-06-05T03:09:22.468Z] File "<frozen importlib._bootstrap_external>", line 883, in exec_module
[2024-06-05T03:09:22.468Z] File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
[2024-06-05T03:09:22.468Z] File "/src/components/test/function_app.py", line 10, in <module>
[2024-06-05T03:09:22.468Z] @app.retry(strategy="fixed_delay", max_retry_count="3",
[2024-06-05T03:09:22.468Z] .
[2024-06-05T03:09:22.473Z] 0 functions found
[2024-06-05T03:09:22.491Z] 0 functions loaded
[2024-06-05T03:09:22.493Z] Looking for extension bundle Microsoft.Azure.Functions.ExtensionBundle at /home/vscode/.azure-functions-core-tools/Functions/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle
I am using poetry, azure function apps and docker container with the following package versions:
- python 3.10
- azure-functions 1.19.0
- azure-core 1.30.1
- azure-identity 1.16.0
- Python model v2 in Azure
- run time version on azure: 4.34.1.1
I did try with azure function 1.19.0; the retry policy is there for timertrigger but I am still getting this annoying issue.
https://github.com/Azure/azure-functions-python-library/blob/bdeb2c2e29dd491129784ccb5cf5b5371b1ce286/azure/functions/decorators/function_app.py#L3190