You are developing a nightly backup verification workflow using Azure Durable Functions in Python. The orchestrator function must periodically call an activity function to check the status of a database backup job. If the backup is not yet complete, the orchestrator must wait for 15 minutes before checking the status again.
You write the following orchestrator function:
python
import azure.durable_functions as df
import time
def orchestrator_function(context: df.DurableOrchestrationContext):
backup_id = context.get_input()
max_attempts = 5
for attempt in range(max_attempts):
status = yield context.call_activity("CheckBackupStatus", backup_id)
if status == "Completed":
return "Success"
# Wait 15 minutes before the next check
time.sleep(900)
return "Failed"
During testing, the function fails because of thread blocking and invalid replay behavior.
Which modification should you make to ensure the orchestrator function runs correctly without blocking execution threads?
- Replace the time.sleep(900) call with yield context.create_timer(context.current_utc_datetime + datetime.timedelta(minutes=15)) after importing datetime.Answer
- BReplace the time.sleep(900) call with await asyncio.sleep(900) after importing the asyncio library.
- CMove the time.sleep(900) call into a new activity function called DelayActivity and call it using yield context.call_activity("DelayActivity", 900).
- DChange the hosting plan of the Function App to a Dedicated (App Service) plan to prevent the orchestrator from timing out during the time.sleep period.