Skip to content

Wait 任务

Wait 任务用于在工作流程中引入延迟或等待特定时间。它可以用于实现定时执行、延迟处理或基于时间的业务逻辑。

核心特性

  1. 时间控制

    • 固定时间等待
    • 动态时间计算
    • 定时执行
  2. 时间表达式

    • ISO 时间格式
    • 相对时间计算
    • 时区处理
  3. 执行控制

    • 超时管理
    • 取消机制
    • 恢复处理

任务参数

参数描述必需/可选
until等待截止时间,支持 ISO 格式日期时间或表达式必需
duration等待时长(毫秒),与 until 二选一必需
timeoutSeconds最大等待时间(秒)可选
timeZone时区设置,默认为 UTC可选

配置示例

1. 基础等待任务

{
  "name": "wait_task",
  "taskReferenceName": "wait_task_ref",
  "type": "WAIT",
  "inputParameters": {
    "duration": "PT10M"
  }
}

2. 定时执行任务

{
  "name": "scheduled_task",
  "taskReferenceName": "scheduled_task_ref",
  "type": "WAIT",
  "inputParameters": {
    "until": "2024-12-31T23:59:59Z",
    "timeZone": "Asia/Shanghai"
  }
}

3. 动态等待时间

{
  "name": "dynamic_wait",
  "taskReferenceName": "dynamic_wait_ref",
  "type": "WAIT",
  "inputParameters": {
    "duration": "${workflow.input.waitTime}",
    "timeoutSeconds": 3600
  }
}

使用场景

1. 延迟处理

{
  "name": "delayed_processing",
  "taskReferenceName": "delayed_processing_ref",
  "type": "WAIT",
  "inputParameters": {
    "duration": "PT1H",
    "timeoutSeconds": 4000,
    "reason": "Allow system cool down"
  }
}

2. 定时任务调度

{
  "name": "scheduled_job",
  "taskReferenceName": "scheduled_job_ref",
  "type": "WAIT",
  "inputParameters": {
    "until": "${workflow.input.scheduledTime}",
    "timeZone": "${workflow.input.timeZone}",
    "jobDetails": {
      "jobType": "maintenance",
      "priority": "normal"
    }
  }
}

最佳实践

  1. 时间设置

    • 使用标准格式
    • 考虑时区影响
    • 设置合理超时
  2. 错误处理

    • 超时处理
    • 取消处理
    • 异常恢复
  3. 资源管理

    • 控制等待数量
    • 监控资源使用
    • 优化调度策略

性能优化

  1. 等待管理

    • 合理设置时间
    • 避免过多等待
    • 优化调度逻辑
  2. 资源利用

    • 减少资源占用
    • 并行处理优化
    • 系统负载均衡

调试技巧

  1. 等待状态追踪

    {
      "inputParameters": {
     "debug": {
       "waitTaskId": "${TASK_ID}",
       "startTime": "${system.currentTimeMillis}",
       "targetTime": "${workflow.input.until}"
     }
      }
    }
  2. 时间监控

    {
      "inputParameters": {
     "monitor": {
       "remainingTime": 0,
       "elapsedTime": 0,
       "status": "WAITING"
     }
      }
    }

错误处理

常见错误

  1. 时间错误

    • 格式无效
    • 时区错误
    • 过期时间
  2. 执行错误

    • 超时异常
    • 取消失败
    • 系统中断

错误响应

{
  "status": "FAILED",
  "error": "WAIT_TASK_ERROR",
  "message": "Wait task execution failed",
  "details": {
    "waitTime": "2024-12-31T23:59:59Z",
    "errorCode": "INVALID_TIME_FORMAT",
    "errorMessage": "Invalid datetime format"
  }
}

监控建议

  1. 时间指标

    • 等待时长统计
    • 完成时间分布
    • 超时比率
  2. 性能指标

    • 资源使用情况
    • 系统负载
    • 响应时间

安全考虑

  1. 时间验证

    • 输入检查
    • 范围限制
    • 格式验证
  2. 资源保护

    • 限制并发数
    • 防止资源耗尽
    • 系统保护

UI 配置指南

  1. 基本配置

    • 设置等待时间
    • 选择时区
    • 配置超时
  2. 高级选项

    • 取消策略
    • 恢复机制
    • 监控设置
  3. 监控面板

    • 等待状态
    • 时间统计
    • 性能监控

飞流云