You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Durable Functions部署报错:无法识别语言及Azure存储连接问题

Durable Functions部署问题:语言识别失败与存储连接异常

问题描述

正在基于Durable Functions构建流程,需并行调用6个函数,全部执行成功后触发存储过程。原流程由Logic Apps实现,因部分函数执行超2分钟触发重启,故迁移至Durable Functions。本地测试(参照微软Python版文档)运行正常,但部署业务函数时遇到以下问题:

  1. 无法识别项目语言
  2. 指定语言后,仍无法识别Azure Storage连接(已创建临时存储账户,本地与部署环境使用同一连接字符串)

相关代码与配置

Function Activity

def main(url: str) -> str:
    """Trigger the function url"""
    resp = requests.get(url)
    if resp.status_code in (200, 201):
        return True
    return False

Function Orchestrator

def orchestrator_function(context: DurableOrchestrationContext):
    FUNC_NAMES = os.environ['TBL_FUNCTIONS']

    tasks = []
    for name in FUNC_NAMES:
        tasks.append(context.call_activity('CWFunctionActivity', os.environ[name]))

    results = yield context.task_all(tasks)
    if all(results):
        result = yield context.call_activity('CWFunctionActivity', os.environ['FORECAST_DATASET_PROC'])
    else:
        result = "Check the function execution logs"

    return result

Function HTTP Starter

async def main(req: HttpRequest, starter: str) -> HttpResponse:
    client = DurableOrchestrationClient(starter)
    instance_id = await client.start_new(req.route_params["functionName"], None, None)

    logging.info(f"Started orchestration with ID = '{instance_id}'.")

    return client.create_check_status_response(req, instance_id)

local.settings.json

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "storage_connection_string",
        "FUNCTIONS_WORKER_RUNTIME": "python",
        "TBL_FUNCTIONS": "['item1', 'item2', 'item3']",
        /*
        "TBL_FUNCTIONS": [
          "TBL_CHARGE_CODES",
          "TBL_EXPENSES",
          "TBL_MEMBERS",
          "TBL_PROJECTS",
          "TBL_PROJECT_TICKETS",
          "TBL_TIME_ENTRIES"
        ],
        */
        "TBL_CHARGE_CODES" : "corresponding_http_url",
        "TBL_EXPENSES": "corresponding_http_url",
        "TBL_MEMBERS" : "corresponding_http_url",
        "TBL_PROJECTS": "corresponding_http_url",
        "TBL_PROJECT_TICKETS": "corresponding_http_url",
        "TBL_TIME_ENTRIES": "corresponding_http_url"
    }
}

问题解决方案

1. 修复项目语言识别问题

  • 确保部署包包含requirements.txt,文件需包含核心依赖:
    azure-functions>=1.17.0
    azure-functions-durable>=1.13.0
    requests>=2.31.0
    
  • 在Azure门户的函数应用→配置→应用设置中,确认FUNCTIONS_WORKER_RUNTIME设置为python,并保存配置
  • 使用官方工具部署:通过Azure Functions Core Tools执行func azure functionapp publish <app-name>,或VS Code Azure扩展部署,避免手动上传不完整文件

2. 修复Azure Storage连接识别问题

  • 验证连接字符串:从Azure门户存储账户→访问密钥复制完整连接字符串,确保无空格、截断或格式错误
  • 核对应用设置:在Azure门户函数应用→配置→应用设置中,确认AzureWebJobsStorage的值与本地local.settings.json完全一致
  • 配置存储权限:为函数应用的系统分配身份(或用户分配身份)授予存储账户的存储队列数据参与者和存储表数据参与者角色
  • 检查存储防火墙:若存储账户启用防火墙,需允许函数应用的IP地址或所属虚拟网络访问

代码优化建议

Orchestrator环境变量解析修复

当前TBL_FUNCTIONS读取的是字符串格式数组,直接遍历会导致错误,需解析为JSON数组:

import json

def orchestrator_function(context: DurableOrchestrationContext):
    FUNC_NAMES = json.loads(os.environ['TBL_FUNCTIONS'])

    tasks = []
    for name in FUNC_NAMES:
        tasks.append(context.call_activity('CWFunctionActivity', os.environ[name]))

    results = yield context.task_all(tasks)
    if all(results):
        result = yield context.call_activity('CWFunctionActivity', os.environ['FORECAST_DATASET_PROC'])
    else:
        result = "Check the function execution logs"

    return result

同时修改local.settings.json中的TBL_FUNCTIONS为标准JSON数组:

"TBL_FUNCTIONS": ["TBL_CHARGE_CODES", "TBL_EXPENSES", "TBL_MEMBERS", "TBL_PROJECTS", "TBL_PROJECT_TICKETS", "TBL_TIME_ENTRIES"]

内容的提问来源于stack exchange,提问作者Aroosh Rana

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 23:25:55