我有一个用 python 编写的 azure 持久函数,带有一个协调器和两个活动函数
orchestrator 调用第一个活动函数,并作为回报接收一个列表变量(名称列表和此列表可以在每次执行函数时都是动态的)
下一步是为每个列表项调用第二个活动函数(顺序处理 - 由于第二个活动函数调用的 api 限制)
#dynamically gets generated by the first activity function payload=[1,2,3,4] tasks = [context.call_activity("secondfunction",ps) for ps in payload] output = yield context.task_all(tasks)
我在扇出方法中使用的不是串行的,但我似乎无法找到我想要做的事情的替代方法。
此外,在 host.json 文件中,我尝试强制在给定时间只能运行一个活动函数,以避免并行处理
"extensions": { "durableTask": { "maxConcurrentActivityFunctions": 1, "maxConcurrentOrchestratorFunctions": 1 } }
还值得注意的是,我无法将整个列表传递给活动函数,就好像我执行活动函数将花费超过 5-10 分钟,这是 azure 函数的超时限制,因此尝试迭代列表编排功能
但结果不是连续的
非常感谢您的反馈
正确答案
您可以尝试使用以下两种方法来实现您的要求:-
方法 1:-
我的function_app.py:-
import azure.functions as func import azure.durable_functions as df myapp = df.dfapp(http_auth_level=func.authlevel.anonymous) # http starter @myapp.route(route="orchestrators/{functionname}") @myapp.durable_client_input(client_name="client") async def http_start(req: func.httprequest, client): function_name = req.route_params.get('functionname') instance_id = await client.start_new(function_name, none) # pass the functionname here response = client.create_check_status_response(req, instance_id) return response # orchestrator @myapp.orchestration_trigger(context_name="context") def hello_orchestrator(context): cities = ["seattle", "tokyo", "london"] tasks = [] for city in cities: tasks.append(context.call_activity("hello", city)) # wait for all tasks to complete results = yield context.task_all(tasks) return results # activity @myapp.activity_trigger(input_name="city") def hello(city: str): print(f"processing {city}...") # your activity function logic goes here result = f"hello {city}!" return result
输出:-
函数 url:-
http://localhost:7071/api/orchestrators/hello_orchestrator
方法 2:-
function_app.py:-
import azure.functions as func import azure.durable_functions as df myApp = df.DFApp(http_auth_level=func.AuthLevel.ANONYMOUS) # HTTP Starter @myApp.route(route="orchestrators/{functionName}") @myApp.durable_client_input(client_name="client") async def http_start(req: func.HttpRequest, client): function_name = req.route_params.get('functionName') instance_id = await client.start_new(function_name, None) # Pass the functionName here response = client.create_check_status_response(req, instance_id) return response # Orchestrator @myApp.orchestration_trigger(context_name="context") def hello_orchestrator(context): # Call the first activity to get a list of names names_list = yield context.call_activity("get_names") # Process each name sequentially using the second activity results = [] for name in names_list: result = yield context.call_activity("process_name", name) results.append(result) return results # First Activity @myApp.activity_trigger def get_names(): # Your logic to retrieve a dynamic list of names goes here # For demonstration purposes, returning a hardcoded list return ["John", "Alice", "Bob"] # Second Activity @myApp.activity_trigger(input_name="name") def process_name(name: str): print(f"Processing {name}...") # Your logic to process each name goes here result = f"Hello {name}!" return result
以上是Azure持久功能:处理列表的详细内容。更多信息请关注PHP中文网其他相关文章!

Python的灵活性体现在多范式支持和动态类型系统,易用性则源于语法简洁和丰富的标准库。1.灵活性:支持面向对象、函数式和过程式编程,动态类型系统提高开发效率。2.易用性:语法接近自然语言,标准库涵盖广泛功能,简化开发过程。

Python因其简洁与强大而备受青睐,适用于从初学者到高级开发者的各种需求。其多功能性体现在:1)易学易用,语法简单;2)丰富的库和框架,如NumPy、Pandas等;3)跨平台支持,可在多种操作系统上运行;4)适合脚本和自动化任务,提升工作效率。

可以,在每天花费两个小时的时间内学会Python。1.制定合理的学习计划,2.选择合适的学习资源,3.通过实践巩固所学知识,这些步骤能帮助你在短时间内掌握Python。

Python适合快速开发和数据处理,而C 适合高性能和底层控制。1)Python易用,语法简洁,适用于数据科学和Web开发。2)C 性能高,控制精确,常用于游戏和系统编程。

学习Python所需时间因人而异,主要受之前的编程经验、学习动机、学习资源和方法及学习节奏的影响。设定现实的学习目标并通过实践项目学习效果最佳。

Python在自动化、脚本编写和任务管理中表现出色。1)自动化:通过标准库如os、shutil实现文件备份。2)脚本编写:使用psutil库监控系统资源。3)任务管理:利用schedule库调度任务。Python的易用性和丰富库支持使其在这些领域中成为首选工具。

要在有限的时间内最大化学习Python的效率,可以使用Python的datetime、time和schedule模块。1.datetime模块用于记录和规划学习时间。2.time模块帮助设置学习和休息时间。3.schedule模块自动化安排每周学习任务。

Python在游戏和GUI开发中表现出色。1)游戏开发使用Pygame,提供绘图、音频等功能,适合创建2D游戏。2)GUI开发可选择Tkinter或PyQt,Tkinter简单易用,PyQt功能丰富,适合专业开发。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

Atom编辑器mac版下载
最流行的的开源编辑器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器