SAP Automation Pilot 定时执行 API 管理技能用于管理 SAP Automation Pilot 中的定时命令执行,包括创建、列出、更新和删除定时执行,支持灵活的调度选项和时区。
用途 该技能面向需要通过 API 对 SAP Automation Pilot 定时执行进行管理的场景,例如为命令设置周期性或一次性执行计划,并对其进行查询、修改、启用、禁用或删除。
前置条件 需要设置以下环境变量:
export AUTOPI_HOSTNAME="emea.autopilot.cloud.sap" export AUTOPI_USERNAME="your-username" export AUTOPI_PASSWORD="your-password" export AUTOPI_DEFAULT_CATALOG="mycommands-<<<TENANT_ID>>>"
支持的完整主机名列表(emea、aus、apac、amer、ksa)参见 ../automation-pilot-content-management-via-api/SKILL.md → Prerequisites。
确保环境中可用 curl。
调度类型 SAP Automation Pilot 支持以下调度类型:
一次性(Once):在指定日期/时间执行一次。 "once": { "month": 12, "day": 31, "hour": 23, "minute": 30 }
每小时(Hourly):在每小时内的指定分钟执行。 "hourly": { "minutes": [0, 15, 30, 45] }
每天(Daily):每天在指定时间执行。 "daily": { "hours": [9], "minutes": [0] }
每周(Weekly):在指定星期几的指定时间执行。 "weekly": { "days": ["MONDAY", "WEDNESDAY", "FRIDAY"], "hours": [9], "minutes": [0] }
每月(Monthly):在每月指定日期执行。 "monthly": { "days": [1, 15], "hours": [9], "minutes": [0] }
每年(Yearly):在每年指定日期执行。 "yearly": { "month": 1, "day": 1, "hour": 0, "minute": 0 }
创建定时执行
curl -s -X POST
-u "$AUTOPI_USERNAME:$AUTOPI_PASSWORD"
-H "Content-Type: application/json"
-d '{
"commandId": "my-catalog:MyCommand:1",
"schedule": {
"timeZone": "Europe/Berlin",
"daily": {
"hours": [9],
"minutes": [0]
}
},
"enabled": true,
"inputValues": {
"param1": "value1"
},
"description": "Daily morning check"
}'
"https://$AUTOPI_HOSTNAME/api/v1/scheduled-executions"
所有 inputValues 条目在传输时都必须是字符串,无论声明的参数类型是什么——参见 ../automation-pilot-content-management-via-api/SKILL.md → "Values Are Always Strings on the Wire"。
管理定时执行
列出所有计划:
curl -s -u "$AUTOPI_USERNAME:$AUTOPI_PASSWORD"
"https://$AUTOPI_HOSTNAME/api/v1/scheduled-executions"
获取计划详情:
SCHEDULE_ID="your-schedule-id"
curl -s -u "$AUTOPI_USERNAME:$AUTOPI_PASSWORD"
"https://$AUTOPI_HOSTNAME/api/v1/scheduled-executions/$SCHEDULE_ID"
启用/禁用计划:
PUT 完整计划体,并将 "enabled" 设置为 true 或 false
curl -s -X PUT
-u "$AUTOPI_USERNAME:$AUTOPI_PASSWORD"
-H "Content-Type: application/json"
-d '<full schedule body with enabled changed>'
"https://$AUTOPI_HOSTNAME/api/v1/scheduled-executions/$SCHEDULE_ID"
删除计划:
curl -s -X DELETE
-u "$AUTOPI_USERNAME:$AUTOPI_PASSWORD"
"https://$AUTOPI_HOSTNAME/api/v1/scheduled-executions/$SCHEDULE_ID"
更新定时执行
curl -s -X PUT
-u "$AUTOPI_USERNAME:$AUTOPI_PASSWORD"
-H "Content-Type: application/json"
-d '{
"commandId": "my-catalog:MyCommand:1",
"schedule": {
"timeZone": "Europe/Berlin",
"daily": {
"hours": [10],
"minutes": [0]
}
},
"enabled": true,
"inputValues": {}
}'
"https://$AUTOPI_HOSTNAME/api/v1/scheduled-executions/$SCHEDULE_ID"
时区
列出可用时区:
curl -s -u "$AUTOPI_USERNAME:$AUTOPI_PASSWORD"
"https://$AUTOPI_HOSTNAME/api/v1/scheduled-executions/time-zones"
常用时区: Etc/UTC:协调世界时(默认) Europe/Berlin:中欧时间(CET/CEST) Europe/London:英国时间(GMT/BST) America/New_York:东部时间(EST/EDT) America/Los_Angeles:太平洋时间(PST/PDT) Asia/Tokyo:日本标准时间 Asia/Singapore:新加坡时间 Australia/Sydney:澳大利亚东部时间
定时执行 Schema 请求体(创建/更新): { "commandId": "catalog:CommandName:version", "description": "Optional description", "correlationId": "optional-correlation-id", "tags": {}, "inputValues": { "param1": "value1" }, "inputReferences": [], "schedule": { "timeZone": "Europe/Berlin", "daily": { "hours": [9], "minutes": [0] } }, "enabled": true }
错误处理 HTTP 状态码: 200:成功(GET、PUT) 201:已创建(POST) 204:无内容(DELETE) 400:错误请求——无效的计划或输入 401:未授权——凭据无效 403:禁止——权限不足 404:未找到——计划不存在 409:冲突——无效状态 429:速率受限
所需权限: 列出/获取计划:Read 创建/更新/删除:Execute
常见错误: 命令未找到(409):Error: Command "catalog:Command:1" not found。请验证命令 ID 存在且你有权访问。 无效计划(400):Error: Invalid schedule configuration。确保只设置一种调度类型(hourly、daily、weekly、monthly 或 yearly)。 计划未触发:原因可能是计划被禁用或时区配置错误。解决方案:GET 该计划并验证 "enabled": true。确认 timeZone 与预期区域匹配——设置为 Europe/Berlin 09:00 的计划与设置为 Etc/UTC 的计划在不同 UTC 时间触发。
示例 示例 1:创建每日健康检查计划 用户:“将我的健康检查命令安排为每天柏林时间上午 9 点运行” 向 /api/v1/scheduled-executions 发送 POST,包含 commandId、enabled: true 以及 "daily": {"hours": [9], "minutes": [0]} 设置 "timeZone": "Europe/Berlin" 从响应中捕获计划 ID 通过 GET 确认计划已启用且时间正确
示例 2:更新计划时间 用户:“将我的计划改为上午 10 点运行,而不是上午 9 点” GET /api/v1/scheduled-executions/$SCHEDULE_ID 获取当前请求体 将响应体中的 hours 值修改为 [10] 将完整更新后的请求体 PUT 回去 确认响应显示新时间
示例 3:创建每 15 分钟监控计划 用户:“每 15 分钟运行我的监控命令” 向 /api/v1/scheduled-executions 发送 POST,包含 "hourly": {"minutes": [0, 15, 30, 45]} 设置 "timeZone": "Etc/UTC" 验证计划已创建并启用