huawei-cloud-functiongraph-trigger-create
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOverview
概述
This skill enables the creation and configuration of scheduled triggers (TIMER type) for Huawei Cloud FunctionGraph functions. It supports Quartz Cron expression format for flexible scheduling configurations.
The trigger allows automatic execution of serverless functions at specified time intervals, making it ideal for:
- Periodic data processing tasks
- Scheduled backup operations
- Regular monitoring and health checks
- Time-based notification systems
本技能支持为华为云FunctionGraph函数创建并配置定时触发器(TIMER类型),采用Quartz Cron表达式格式实现灵活的调度配置。
该触发器可让无服务器函数在指定时间间隔自动执行,非常适用于以下场景:
- 周期性数据处理任务
- 定时备份操作
- 常规监控与健康检查
- 基于时间的通知系统
Prerequisites
前提条件
Before using this skill, ensure the following requirements are met:
- Python Environment: Python 3.9+ installed
- SDK Installation: Install FunctionGraph SDK:
pip install huaweicloudsdkfunctiongraph - Environment Variables: Configure the following environment variables:
- : Huawei Cloud Access Key
HUAWEI_AK - : Huawei Cloud Secret Key
HUAWEI_SK - : Target region (e.g.,
HUAWEI_REGION)cn-north-4 - : Project ID
HUAWEI_PROJECT_ID
- FunctionGraph Function: Target function must already exist in the specified region
- Network Access: Stable network connection to Huawei Cloud API endpoints
使用本技能前,请确保满足以下要求:
- Python环境:已安装Python 3.9及以上版本
- SDK安装:安装FunctionGraph SDK:
pip install huaweicloudsdkfunctiongraph - 环境变量:配置以下环境变量:
- :华为云访问密钥
HUAWEI_AK - :华为云私有密钥
HUAWEI_SK - :目标区域(例如:
HUAWEI_REGION)cn-north-4 - :项目ID
HUAWEI_PROJECT_ID
- FunctionGraph函数:目标函数已在指定区域创建
- 网络访问:能够稳定连接华为云API端点
Usage
使用方法
Basic Command Structure
基础命令结构
bash
cd scripts
python create_trigger.py \
--function-urn "urn:fss:cn-north-4:project_id:function:default:my-function:latest" \
--name "daily-trigger" \
--schedule "0 0 2 * * ?" \
--schedule-type "Cron" \
--status "ACTIVE"bash
cd scripts
python create_trigger.py \
--function-urn "urn:fss:cn-north-4:project_id:function:default:my-function:latest" \
--name "daily-trigger" \
--schedule "0 0 2 * * ?" \
--schedule-type "Cron" \
--status "ACTIVE"Examples
示例
Cron Expression Trigger
Cron表达式触发器
bash
cd scripts
python create_trigger.py \
--function-urn "urn:fss:cn-north-4:project_id:function:default:my-function:latest" \
--name "daily-trigger" \
--schedule "0 0 8 * * ?" \
--schedule-type "Cron"bash
cd scripts
python create_trigger.py \
--function-urn "urn:fss:cn-north-4:project_id:function:default:my-function:latest" \
--name "daily-trigger" \
--schedule "0 0 8 * * ?" \
--schedule-type "Cron"Fixed Rate Trigger
固定频率触发器
bash
cd scripts
python create_trigger.py \
--function-urn "urn:fss:cn-north-4:project_id:function:default:my-function:latest" \
--name "every-5min" \
--schedule "5m" \
--schedule-type "Rate"bash
cd scripts
python create_trigger.py \
--function-urn "urn:fss:cn-north-4:project_id:function:default:my-function:latest" \
--name "every-5min" \
--schedule "5m" \
--schedule-type "Rate"Cron Expression Format
Cron表达式格式
FunctionGraph uses Quartz Cron format with 6 or 7 fields:
┌───────────── second (0-59)
│ ┌───────────── minute (0-59)
│ │ ┌───────────── hour (0-23)
│ │ │ ┌───────────── day of month (1-31)
│ │ │ │ ┌───────────── month (1-12)
│ │ │ │ │ ┌───────────── day of week (1-7, 1=Sunday)
│ │ │ │ │ │
* * * * * ?For detailed Cron expression reference including special characters and common examples, see Cron Expression Reference.
FunctionGraph采用Quartz Cron格式,包含6或7个字段:
┌───────────── 秒 (0-59)
│ ┌───────────── 分 (0-59)
│ │ ┌───────────── 时 (0-23)
│ │ │ ┌───────────── 日 (1-31)
│ │ │ │ ┌───────────── 月 (1-12)
│ │ │ │ │ ┌───────────── 星期 (1-7, 1=周日)
│ │ │ │ │ │
* * * * * ?如需了解包含特殊字符和常见示例的详细Cron表达式参考,请查看Cron表达式参考。
Parameters Confirmation
参数确认
Before creating the trigger, confirm the following parameters:
| Parameter | Required | Description | Example |
|---|---|---|---|
| Yes | Target function URN | |
| Yes | Trigger name (1-64 chars) | |
| Yes | Cron expression or Rate value | |
| No | | |
| No | | |
| No | Additional user event data | |
创建触发器前,请确认以下参数:
| 参数 | 是否必填 | 描述 | 示例 |
|---|---|---|---|
| 是 | 目标函数URN | |
| 是 | 触发器名称(1-64字符) | |
| 是 | Cron表达式或频率值 | |
| 否 | | |
| 否 | | |
| 否 | 附加用户事件数据 | |
Confirmation Checklist
确认清单
- Function URN is correct and function exists
- Cron expression has been validated
- Trigger name follows naming conventions
- IAM permissions are sufficient
- Region matches the function location
- 函数URN正确且函数已存在
- Cron表达式已验证
- 触发器名称符合命名规范
- IAM权限足够
- 区域与函数所在位置匹配
Output Format
输出格式
Success Response
成功响应
json
{
"status": "success",
"trigger_id": "timer-xxx-xxx-xxx",
"trigger_name": "daily-trigger",
"trigger_type": "TIMER",
"schedule": "0 0 2 * * ?",
"enable_status": "ACTIVE",
"message": "Trigger created successfully"
}json
{
"status": "success",
"trigger_id": "timer-xxx-xxx-xxx",
"trigger_name": "daily-trigger",
"trigger_type": "TIMER",
"schedule": "0 0 2 * * ?",
"enable_status": "ACTIVE",
"message": "Trigger created successfully"
}Error Response
错误响应
json
{
"status": "failed",
"error_code": "TriggerAlreadyExists",
"message": "Trigger with the same name already exists"
}For complete error codes and troubleshooting information, see Cron Expression Reference.
json
{
"status": "failed",
"error_code": "TriggerAlreadyExists",
"message": "Trigger with the same name already exists"
}完整错误码和故障排除信息,请查看Cron表达式参考。
Verification Method
验证方法
After creating the trigger, verify the configuration:
创建触发器后,请按以下步骤验证配置:
1. List Function Triggers
1. 列出函数触发器
Navigate to FunctionGraph console → Function details → Triggers tab to view all triggers
进入FunctionGraph控制台 → 函数详情 → 触发器标签页,查看所有触发器
2. Check Trigger Details
2. 查看触发器详情
Navigate to FunctionGraph console → Function details → Triggers → View trigger details
进入FunctionGraph控制台 → 函数详情 → 触发器 → 查看触发器详情
3. Monitor Trigger Execution
3. 监控触发器执行
Navigate to FunctionGraph console → Function details → Triggers → View execution history
Expected indicators:
- Trigger status: Active
- Next execution time: Correctly calculated
- Execution history: No failed invocations
进入FunctionGraph控制台 → 函数详情 → 触发器 → 查看执行历史
预期指标:
- 触发器状态:Active
- 下次执行时间:计算正确
- 执行历史:无失败调用
Best Practices
最佳实践
Cron Expression Best Practices
Cron表达式最佳实践
- Avoid frequent executions: Use intervals ≥ 5 minutes unless necessary
- Consider timezone: FunctionGraph uses UTC by default
- Use for unused day field: Either day-of-month or day-of-week should use
?? - Validate before creation: Test expressions using online Cron validators
- 避免频繁执行:除非必要,使用≥5分钟的间隔
- 考虑时区:FunctionGraph默认使用UTC时区
- 对未使用的日期字段使用:日或星期字段应使用
?? - 创建前验证:使用在线Cron验证工具测试表达式
Naming Conventions
命名规范
- Use descriptive names: ,
daily-data-synchourly-health-check - Follow pattern:
[frequency]-[purpose] - Maximum 64 characters
- Use lowercase with hyphens
- 使用描述性名称:、
daily-data-synchourly-health-check - 遵循模式:
[频率]-[用途] - 最多64个字符
- 使用小写字母加连字符
Security Considerations
安全注意事项
- Least privilege: Grant minimal IAM permissions
- Enable encryption: Use KMS for sensitive function inputs
- Monitor executions: Set up Cloud Eye alarms for failures
- Rate limiting: Configure appropriate retry parameters
- 最小权限原则:授予最小IAM权限
- 启用加密:对敏感函数输入使用KMS加密
- 监控执行:为失败情况设置Cloud Eye告警
- 速率限制:配置合适的重试参数
Operational Recommendations
操作建议
- Start with disabled status for testing
- Document trigger purpose in description field
- Set appropriate retries for transient failures
- Monitor first executions after enabling
- 测试时先设置为禁用状态
- 在描述字段中记录触发器用途
- 为临时故障设置合适的重试次数
- 启用后监控首次执行情况
Reference Documents
参考文档
For detailed information, refer to:
- SDK Installation Guide
- IAM Policies
- Verification Method
- Acceptance Criteria
- Cron Expression Reference
如需详细信息,请参考:
- SDK安装指南
- IAM策略
- 验证方法
- 验收标准
- Cron表达式参考
Important Notes
重要说明
Compatibility Notes
兼容性说明
This skill is designed to work with Huawei Cloud FunctionGraph API. The field helps with skill discovery and categorization, while the field follows semantic versioning for skill updates.
tagsversion本技能专为华为云FunctionGraph API设计。字段用于技能发现和分类,字段遵循语义化版本控制用于技能更新。
tagsversionLimitations
限制
- Maximum triggers: Each function supports up to 10 triggers by default
- Cron precision: Second-level scheduling may have minor delays
- Timeout handling: Function timeout should be less than trigger interval
- Cold start: First executions may have additional latency
- 最大触发器数量:每个函数默认最多支持10个触发器
- Cron精度:秒级调度可能存在轻微延迟
- 超时处理:函数超时时间应小于触发器间隔
- 冷启动:首次执行可能存在额外延迟
Cost Implications
成本影响
- No additional cost for trigger configuration
- Function execution billed per invocation
- Consider execution frequency for cost optimization
- 触发器配置无额外费用
- 函数执行按调用次数计费
- 需考虑执行频率以优化成本
Common Pitfalls
常见陷阱
- Wrong timezone: Remember FunctionGraph uses UTC
- Overlapping schedules: Multiple triggers may cause concurrent executions
- Long-running functions: Ensure function completes before next trigger
- Cron syntax errors: Validate expression format before deployment
For troubleshooting and error codes, refer to Cron Expression Reference.
Related Skills:
huawei-cloud-functiongraph-function-createhuawei-cloud-functiongraph-deploy
- 时区错误:记住FunctionGraph使用UTC时区
- 调度重叠:多个触发器可能导致并发执行
- 长时间运行的函数:确保函数在下次触发前完成
- Cron语法错误:部署前验证表达式格式
故障排除和错误码详情,请查看Cron表达式参考。
相关技能:
huawei-cloud-functiongraph-function-createhuawei-cloud-functiongraph-deploy