产品文档已发布
RAILWISE-TSM 自动化监测流程编排
TSM平台自动化监测工作流的完整编排指南,涵盖触发器配置、条件分支、异常处理与定时任务调度
产品文档
RAILWISE-TSM 自动化监测流程编排
Section titled “RAILWISE-TSM 自动化监测流程编排”适用版本: TSM v3.2+ 阅读对象: 监测项目负责人、自动化工程师 相关标准: GB 50497-2019《建筑基坑工程监测技术标准》
RAILWISE-TSM 的自动化监测流程编排引擎(Workflow Engine)允许用户通过可视化界面或 YAML 配置定义完整的监测作业流水线。从数据采集触发、质量校验、预警判断到报告生成,全流程无需人工干预。
1.1 核心能力
Section titled “1.1 核心能力”| 能力项 | 说明 | 典型场景 |
|---|---|---|
| 触发器驱动 | 支持时间/事件/数据阈值多种触发方式 | 定时巡检、超限自动报警 |
| 条件分支 | 基于监测数据动态选择执行路径 | 不同预警等级触发不同响应 |
| 异常重试 | 自动重试失败节点,支持降级策略 | 网络中断后自动恢复采集 |
| 并行执行 | 多测点、多仪器同步作业 | 大型基坑多点同时监测 |
2. 工作流核心概念
Section titled “2. 工作流核心概念”2.1 工作流定义(Workflow Definition)
Section titled “2.1 工作流定义(Workflow Definition)”工作流由**节点(Node)和边(Edge)**组成的有向图:
# 工作流定义示例:基坑自动化日报workflow: name: "foundation-pit-daily-report" version: "1.0" trigger: type: "cron" expr: "0 8 * * *" # 每日08:00执行
nodes: - id: "collect-data" type: "data-collection" config: instruments: ["TS-01", "TS-02", "TS-03"] timeout: 300
- id: "validate-data" type: "data-validation" config: rules: ["range-check", "trend-check", "outlier-check"]
- id: "check-threshold" type: "condition" config: expression: "max_delta > threshold_yellow"
- id: "generate-normal-report" type: "report-generation" config: template: "daily-standard" when: "check-threshold == false"
- id: "generate-alert-report" type: "report-generation" config: template: "daily-alert" notify: ["sms", "email"] when: "check-threshold == true"
- id: "archive" type: "data-archive" config: retention_days: 365
edges: - from: "collect-data" to: "validate-data" - from: "validate-data" to: "check-threshold" - from: "check-threshold" to: "generate-normal-report" - from: "check-threshold" to: "generate-alert-report" - from: "generate-normal-report" to: "archive" - from: "generate-alert-report" to: "archive"2.2 节点类型总览
Section titled “2.2 节点类型总览”| 节点类型 | 标识 | 功能描述 |
|---|---|---|
| 数据采集 | data-collection |
驱动全站仪/传感器执行测量 |
| 数据校验 | data-validation |
执行范围、趋势、异常值检查 |
| 条件判断 | condition |
基于表达式分支执行 |
| 数据转换 | data-transform |
格式转换、单位换算、坐标转换 |
| 报告生成 | report-generation |
按模板生成PDF/Word/Excel报告 |
| 消息通知 | notification |
发送短信/邮件/企业微信/钉钉 |
| 数据归档 | data-archive |
历史数据压缩归档 |
| 外部调用 | webhook |
调用第三方API |
| 人工审批 | manual-approval |
暂停等待人工确认 |
| 子工作流 | sub-workflow |
嵌套调用其他工作流 |
3. 触发器配置详解
Section titled “3. 触发器配置详解”3.1 定时触发(Cron Trigger)
Section titled “3.1 定时触发(Cron Trigger)”最常用的触发方式,支持标准 Cron 表达式:
trigger: type: "cron" expr: "0 */4 * * *" # 每4小时执行 timezone: "Asia/Shanghai" # 默认上海时区 skip_on_holiday: false # 节假日是否跳过4. 条件分支与动态路由
Section titled “4. 条件分支与动态路由”4.1 表达式语法
Section titled “4.1 表达式语法”条件节点支持类 JavaScript 表达式:
- id: "route-by-alert-level" type: "condition" config: expression: | alert_level === 'red' ? 'emergency-branch' : alert_level === 'yellow' ? 'warning-branch' : 'normal-branch'4.2 可用变量上下文
Section titled “4.2 可用变量上下文”| 变量名 | 类型 | 说明 |
|---|---|---|
data |
Object | 上游节点输出的完整数据 |
data.values |
Array | 监测值数组 |
data.max_delta |
Number | 最大变化量(mm) |
data.alert_level |
String | 当前预警等级 |
trigger.time |
Date | 触发时间 |
workflow.execution_id |
String | 本次执行唯一ID |
env.PROJECT_ID |
String | 环境变量 |
4.3 多分支并行示例
Section titled “4.3 多分支并行示例”nodes: - id: "classify" type: "condition" config: branches: - name: "red-alert" expression: "data.max_delta >= threshold_red" - name: "yellow-alert" expression: "data.max_delta >= threshold_yellow && data.max_delta < threshold_red" - name: "normal" expression: "data.max_delta < threshold_yellow"5. 异常处理与重试机制
Section titled “5. 异常处理与重试机制”5.1 节点级重试配置
Section titled “5.1 节点级重试配置”每个节点可独立配置故障恢复策略:
- id: "collect-data" type: "data-collection" config: instruments: ["TS-01"] retry: max_attempts: 3 backoff: "exponential" # 固定(fixed) / 线性(linear) / 指数(exponential) initial_delay: 10 # 首次重试等待秒数 max_delay: 300 on_failure: "fallback" # 失败策略:abort / fallback / continue fallback: type: "use-last-valid" # 使用上次有效数据5.2 全局异常处理器
Section titled “5.2 全局异常处理器”workflow: on_error: - type: "notification" config: channels: ["sms", "email"] recipients: ["admin@railwise.cn"] template: "workflow-error-alert" - type: "webhook" config: url: "https://monitoring.railwise.cn/api/alerts" method: "POST"| 策略 | 行为 | 适用场景 |
|---|---|---|
abort |
终止整个工作流 | 关键节点失败 |
fallback |
使用备用数据/逻辑 | 采集失败时用历史数据 |
continue |
跳过当前节点继续 | 非关键校验节点 |
retry |
按策略重试 | 网络瞬断 |
| ::: |
6. 定时任务调度与资源管理
Section titled “6. 定时任务调度与资源管理”6.1 调度策略
Section titled “6.1 调度策略”TSM 使用内部调度器管理并发工作流:
workflow: scheduling: priority: 5 # 1-10,数值越高优先级越高 max_concurrent: 2 # 同一工作流最大并发实例数 queue_timeout: 600 # 排队超时秒数 resource_pool: "high-precision-instruments" # 资源池绑定6.2 资源池配置
Section titled “6.2 资源池配置”当多个工作流共享同一台全站仪时,需配置资源互斥:
# 在系统管理后台配置resource_pools: - name: "high-precision-instruments" resources: - "TS-01" - "TS-02" allocation: "fifo" # fifo / priority / round-robin- 避免工作流 A 占用仪器 X 等待仪器 Y,同时工作流 B 占用仪器 Y 等待仪器 X
- 建议为互斥资源设置统一的获取顺序
- 使用
max_wait_time自动释放超时占用的资源
7. 实战案例:盾构穿越高架桥自动化监测
Section titled “7. 实战案例:盾构穿越高架桥自动化监测”7.1 场景描述
Section titled “7.1 场景描述”盾构隧道侧穿高架桥墩期间,需每 2 小时自动执行:
- 桥墩位移监测(3台全站仪)
- 数据质量校验
- 变化速率判断
- 超限则立即报警并生成应急报告
- 正常则归档并更新趋势图
7.2 完整工作流配置
Section titled “7.2 完整工作流配置”workflow: name: "shield-crossing-bridge-monitoring" version: "2.1" trigger: type: "cron" expr: "0 */2 * * *"
nodes: - id: "collect-ts01" type: "data-collection" config: instrument: "TS-01" points: ["P-01", "P-02", "P-03"] retry: max_attempts: 3 backoff: "exponential"
- id: "collect-ts02" type: "data-collection" config: instrument: "TS-02" points: ["P-04", "P-05", "P-06"] retry: max_attempts: 3 backoff: "exponential"
- id: "collect-ts03" type: "data-collection" config: instrument: "TS-03" points: ["P-07", "P-08", "P-09"] retry: max_attempts: 3 backoff: "exponential"
- id: "merge-data" type: "data-transform" config: operation: "merge" sources: ["collect-ts01", "collect-ts02", "collect-ts03"]
- id: "validate" type: "data-validation" config: rules: - type: "range-check" min: -50.0 max: 50.0 - type: "trend-check" max_rate: 2.0 # mm/2h
- id: "check-alert" type: "condition" config: branches: - name: "red" expression: "data.max_delta >= 10.0 || data.max_rate >= 2.0" - name: "yellow" expression: "data.max_delta >= 6.0 || data.max_rate >= 1.5" - name: "normal" expression: "data.max_delta < 6.0 && data.max_rate < 1.5"
- id: "report-normal" type: "report-generation" config: template: "routine-2h" when: "check-alert == 'normal'"
- id: "report-yellow" type: "report-generation" config: template: "alert-yellow-2h" notify: ["email"] when: "check-alert == 'yellow'"
- id: "report-red" type: "report-generation" config: template: "alert-red-emergency" notify: ["sms", "email", "dingtalk"] when: "check-alert == 'red'"
- id: "archive" type: "data-archive" config: retention_days: 730
edges: - from: "merge-data" to: "validate" - from: "validate" to: "check-alert" - from: "check-alert" to: "report-normal" - from: "check-alert" to: "report-yellow" - from: "check-alert" to: "report-red" - from: "report-normal" to: "archive" - from: "report-yellow" to: "archive" - from: "report-red" to: "archive"
on_error: - type: "notification" config: channels: ["sms"] recipients: ["duty-engineer"]8. 监控与运维
Section titled “8. 监控与运维”8.1 工作流执行状态查看
Section titled “8.1 工作流执行状态查看”在 TSM Web 控制台导航至:自动化 > 工作流实例
| 状态 | 含义 | 操作 |
|---|---|---|
| 🟢 运行中 | 正在执行 | 可查看实时日志 |
| 🔵 排队中 | 等待资源 | 可调整优先级 |
| ⚪ 已完成 | 成功结束 | 查看输出报告 |
| 🟡 已暂停 | 等待人工审批 | 审批后继续 |
| 🔴 已失败 | 执行出错 | 查看错误日志并重试 |
| ⚫ 已取消 | 手动取消 | 可重新触发 |
8.2 日志与诊断
Section titled “8.2 日志与诊断”# 通过 CLI 查看工作流日志railwise-tsm workflow logs --id <execution-id> --tail 100
# 导出完整执行记录railwise-tsm workflow export --id <execution-id> --format json --output ./run-log.json9. 最佳实践
Section titled “9. 最佳实践”- 保持工作流精简:单个工作流节点数建议不超过 20 个,复杂逻辑拆分为子工作流
- 设置合理的超时:采集节点超时建议 ≥ 仪器单次测量周期的 3 倍
- 版本管理:工作流变更后自动创建版本,支持一键回滚
- 测试先行:使用“手动触发”模式在测试环境验证后再启用定时调度
- 文档注释:在 YAML 中添加
description字段说明每个节点的业务意图
