Im using a HTTP trigger to trigger an Orchestrator Function that runs multiple activity functions. The Http trigger is called every few minutes to retrieve the status of the Orchestration. The activity functions require an external token for certain operations. This token is send with the HTTP trigger to the Orchestrator. To avoid using an expired token when the Orchestrator runs longer, I included an external event into the Http trigger that sends a new token on each call of the trigger, since I didn't find another way to send new data to a running Orchestrator. Now if I add the wait_for_external_event function after my activity functions in the Orchestrator everything runs properly. But if I set it before the activities are called it causes the Orchestrator to stop working. The client.get_status function of the HTTP trigger returns a failed status after the first run.
I am not sure as to why this is, from my understanding it should not make a difference as to when I wait for the external event. Is there any reason why this is happening? In the monitoring the Orchestrator is still shown as "running".
This is my http trigger:
import logging
import azure.functions as func
import azure.durable_functions as df
import json
import uuid
from azure.durable_functions.models.OrchestrationRuntimeStatus import OrchestrationRuntimeStatus
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
try:
client = df.DurableOrchestrationClient(starter)
params = {}
for key, value in req.params.items():
params[key] = value
for key, value in _get_json(req).items():
params[key] = value
access_token = params["accessToken"]
azure_call_id = params.get("azureCallId")
if not azure_call_id:
azure_call_id = await client.start_new('TestOrchestrator',
instance_id=None,
client_input=params)
status = await client.get_status(azure_call_id)
if status.runtime_status == OrchestrationRuntimeStatus.Pending \
or status.runtime_status == OrchestrationRuntimeStatus.Running \
or status.runtime_status == OrchestrationRuntimeStatus.ContinuedAsNew:
await client.raise_event(azure_call_id, 'RefreshToken', {'accessToken': access_token})
return response
except Exception as e:
logging.error(f"Exception caught: {str(e)}")