Temporal 集成
Temporal 集成
Section titled “Temporal 集成”Wippy 集成 Temporal.io 以实现持久化 workflow 执行、自动重放以及可在重启后继续运行的长时间运行进程。
temporal.client 条目类型定义与 Temporal 服务器的连接。
- name: temporal_client kind: temporal.client address: "localhost:7233" namespace: "default" lifecycle: auto_start: true| 字段 | 描述 |
|---|---|
address | Temporal 服务器地址 (host:port) |
| 字段 | 默认值 | 描述 |
|---|---|---|
namespace | ”default” | Temporal 命名空间 |
tq_prefix | "" | 所有操作的任务队列名称前缀 |
connection_timeout | ”10s” | 连接超时时间 |
keep_alive_time | ”30s” | 保活间隔 |
keep_alive_timeout | ”10s” | 保活超时时间 |
- name: temporal_client kind: temporal.client address: "localhost:7233" auth: type: noneAPI Key (Temporal Cloud)
Section titled “API Key (Temporal Cloud)”通过以下方式之一提供 API key:
# 直接指定值- name: temporal_client kind: temporal.client address: "your-namespace.tmprl.cloud:7233" namespace: "your-namespace" auth: type: api_key api_key: "your-api-key"
# 从环境变量读取- name: temporal_client kind: temporal.client address: "your-namespace.tmprl.cloud:7233" namespace: "your-namespace" auth: type: api_key api_key_env: "TEMPORAL_API_KEY"
# 从文件读取- name: temporal_client kind: temporal.client address: "your-namespace.tmprl.cloud:7233" namespace: "your-namespace" auth: type: api_key api_key_file: "/etc/secrets/temporal-api-key"以 _env 结尾的字段引用系统中定义的环境变量。有关配置环境存储和变量的详细信息,请参阅环境系统。
- name: temporal_client kind: temporal.client address: "temporal.example.com:7233" namespace: "production" auth: type: mtls cert_file: "/path/to/client.pem" key_file: "/path/to/client.key" tls: enabled: true ca_file: "/path/to/ca.pem"证书和密钥也可以作为 PEM 字符串或从环境变量中提供:
auth: type: mtls cert_pem: | -----BEGIN CERTIFICATE----- ... -----END CERTIFICATE----- key_pem_env: "TEMPORAL_CLIENT_KEY"TLS 配置
Section titled “TLS 配置”tls: enabled: true ca_file: "/path/to/ca.pem" server_name: "temporal.example.com" # 覆盖服务器名称验证 insecure_skip_verify: false # 跳过验证(仅用于开发环境)health_check: enabled: true interval: "30s"Worker 配置
Section titled “Worker 配置”temporal.worker 条目类型定义执行 workflow 和 activity 的 worker。
- name: worker kind: temporal.worker client: app:temporal_client task_queue: "my-app-queue" lifecycle: auto_start: true depends_on: - app:temporal_client| 字段 | 描述 |
|---|---|
client | 对 temporal.client 条目的引用 |
task_queue | 任务队列名称 |
Worker 选项
Section titled “Worker 选项”微调 worker 行为:
- name: worker kind: temporal.worker client: app:temporal_client task_queue: "my-app-queue" worker_options: # 并发 max_concurrent_activity_execution_size: 1000 max_concurrent_workflow_task_execution_size: 1000 max_concurrent_local_activity_execution_size: 1000 max_concurrent_session_execution_size: 1000
# 轮询器 max_concurrent_activity_task_pollers: 20 max_concurrent_workflow_task_pollers: 20
# 速率限制 worker_activities_per_second: 0 # 0 = 无限制 worker_local_activities_per_second: 0 task_queue_activities_per_second: 0
# 超时 sticky_schedule_to_start_timeout: "5s" worker_stop_timeout: "0s" deadlock_detection_timeout: "0s"
# 功能标志 enable_logging_in_replay: false enable_session_worker: false disable_workflow_worker: false local_activity_worker_only: false disable_eager_activities: false
# 版本控制 deployment_name: "" build_id: "" build_id_env: "BUILD_ID" # 从环境变量读取 use_versioning: false default_versioning_behavior: "pinned" # 或 "auto_upgrade"以 _env 结尾的字段引用通过环境系统条目定义的环境变量。
版本控制行为
Section titled “版本控制行为”当启用 use_versioning 时,default_versioning_behavior 控制新的工作流运行如何选择 worker 构建 ID:
| 值 | 行为 |
|---|---|
pinned | 工作流在整个运行期间保持在启动时所用的构建 ID 上 |
auto_upgrade | 工作流可在每个任务后在最新兼容的构建 ID 上恢复 |
当 build_id 为空时,build_id_env 从指定的环境变量读取构建 ID。
Session Worker
Section titled “Session Worker”enable_session_worker: true 允许 worker 运行 Temporal Sessions:一系列固定到单个 worker 的活动(当活动需要共享本地状态如临时目录或打开的连接时很有用)。max_concurrent_session_execution_size 限制 worker 上的并发会话数。
| 选项 | 默认值 |
|---|---|
max_concurrent_activity_execution_size | 1000 |
max_concurrent_workflow_task_execution_size | 1000 |
max_concurrent_local_activity_execution_size | 1000 |
max_concurrent_session_execution_size | 1000 |
max_concurrent_activity_task_pollers | 20 |
max_concurrent_workflow_task_pollers | 20 |
sticky_schedule_to_start_timeout | 5s |
version: "1.0"namespace: app
entries: - name: temporal_client kind: temporal.client address: "localhost:7233" namespace: "default" lifecycle: auto_start: true
- name: worker kind: temporal.worker client: app:temporal_client task_queue: "orders" lifecycle: auto_start: true depends_on: - app:temporal_client
- name: order_workflow kind: workflow.lua source: file://order_workflow.lua method: main modules: - funcs - time meta: temporal: workflow: worker: app:worker
- name: charge_payment kind: function.lua source: file://payment.lua method: charge modules: - http_client - json meta: temporal: activity: worker: app:worker- Activities - Activity 定义
- Workflows - Workflow 实现