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

如何将OrchestrationRuntimeStatus字符串转换为对应整数数值

OrchestrationRuntimeStatus 字符串转对应整数值的方法

OrchestrationRuntimeStatus 是 Azure WebJobs SDK 定义的强类型枚举,本身所有取值与数值的绑定关系是固定的,你可以根据使用场景选择以下两种方式获取对应整数:

.NET 代码环境处理

如果你的代码运行在 .NET 环境中,直接做枚举转换即可:

  • 先将拿到的字符串转换为 OrchestrationRuntimeStatus 枚举类型
  • 再将枚举值强制转换为 int 类型,就能得到对应的整数值

示例代码:

// 待转换的状态字符串
string runtimeStatus = "Running";

// 安全转换写法,ignoreCase设为true可忽略大小写匹配
if (Enum.TryParse<OrchestrationRuntimeStatus>(runtimeStatus, ignoreCase: true, out var statusEnum))
{
    int statusValue = (int)statusEnum;
    // 此处statusValue取值为0
}

如果你拿到的返回值本身就是 OrchestrationRuntimeStatus 枚举类型,不需要做字符串转换,直接强制转int即可。

非.NET 环境/离线映射处理

如果是其他语言环境,你可以直接使用官方固定的映射关系做匹配,对应关系如下:

  • Running: 0
  • Completed: 1
  • ContinuedAsNew: 2
  • Failed: 3
  • Canceled: 4
  • Terminated: 5
  • Pending: 6
  • Unknown: -1

以Python为例的实现参考:

ORCHESTRATION_STATUS_MAP = {
    "Running": 0,
    "Completed": 1,
    "ContinuedAsNew": 2,
    "Failed": 3,
    "Canceled": 4,
    "Terminated": 5,
    "Pending": 6,
    "Unknown": -1
}

# 转换示例
status_str = "Completed"
status_code = ORCHESTRATION_STATUS_MAP.get(status_str)
# 此处status_code取值为1

注意:匹配时建议先统一字符串大小写,避免因大小写不一致导致匹配失败。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 20:15:07