Im使用HTTP触发器触发运行多个活动函数的Orchestrator函数。Http触发器每隔几分钟调用一次,以检索业务流程的状态。对于某些操作,活动函数需要外部令牌。此令牌与HTTP触发器一起发送到编排器。为了避免在Orchestrator运行更长时间时使用过期的令牌,我在Http触发器中包含了一个外部事件,该事件在每次调用触发器时发送一个新令牌,因为我没有找到其他方法将新数据发送到正在运行的Orchestrator。现在,如果我在Orchestrator中的活动函数之后添加wait_for_external_事件函数,那么一切都会正常运行。但如果在调用活动之前设置它,则会导致编排器停止工作。HTTP触发器的client.get_status函数在第一次运行后返回失败状态
我不确定这是为什么,从我的理解来看,这不应该对我等待外部事件的时间产生影响。发生这种情况有什么原因吗?在监视中,编排器仍显示为“正在运行”
这是我的http触发器:
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)}")
目前没有回答
相关问题 更多 >
编程相关推荐