事件订阅允许您在 Cloudflare 账户中发生事件时接收消息。Cloudflare 产品(例如 KV、Workers AI、Workers)可以将结构化事件发布到队列,然后您可以使用 Workers 或 HTTP 拉取消费者来消费这些事件,以构建自定义工作流、集成或逻辑。
你可以部署一个 Worker 来消费构建事件并将通知发送到 Slack、Discord 或任何 webhook 端点:
该模板会为以下情况发送通知:
- 包含预览或实时部署 URL 的成功构建
- 包含错误消息的失败构建
- 已取消的构建
你可以自定义 Worker 以按 webhook 提供商格式化消息。有关设置说明,请参阅模板 README ↗。
在构建开始时触发。
示例:
{
"type": "cf.workersBuilds.worker.build.started",
"source": {
"type": "workersBuilds.worker",
"workerName": "my-worker"
},
"payload": {
"buildUuid": "build-12345678-90ab-cdef-1234-567890abcdef",
"status": "running",
"buildOutcome": null,
"createdAt": "2025-05-01T02:48:57.132Z",
"initializingAt": "2025-05-01T02:48:58.132Z",
"runningAt": "2025-05-01T02:48:59.132Z",
"stoppedAt": null,
"buildTriggerMetadata": {
"buildTriggerSource": "push_event",
"branch": "main",
"commitHash": "abc123def456",
"commitMessage": "Fix bug in authentication",
"author": "[email protected]",
"buildCommand": "npm run build",
"deployCommand": "wrangler deploy",
"rootDirectory": "/",
"repoName": "my-worker-repo",
"providerAccountName": "github-user",
"providerType": "github"
}
},
"metadata": {
"accountId": "f9f79265f388666de8122cfb508d7776",
"eventSubscriptionId": "1830c4bb612e43c3af7f4cada31fbf3f",
"eventSchemaVersion": 1,
"eventTimestamp": "2025-05-01T02:48:57.132Z"
}
}在构建失败时触发。
示例:
{
"type": "cf.workersBuilds.worker.build.failed",
"source": {
"type": "workersBuilds.worker",
"workerName": "my-worker"
},
"payload": {
"buildUuid": "build-12345678-90ab-cdef-1234-567890abcdef",
"status": "failed",
"buildOutcome": "failure",
"createdAt": "2025-05-01T02:48:57.132Z",
"initializingAt": "2025-05-01T02:48:58.132Z",
"runningAt": "2025-05-01T02:48:59.132Z",
"stoppedAt": "2025-05-01T02:50:00.132Z",
"buildTriggerMetadata": {
"buildTriggerSource": "push_event",
"branch": "main",
"commitHash": "abc123def456",
"commitMessage": "Fix bug in authentication",
"author": "[email protected]",
"buildCommand": "npm run build",
"deployCommand": "wrangler deploy",
"rootDirectory": "/",
"repoName": "my-worker-repo",
"providerAccountName": "github-user",
"providerType": "github"
}
},
"metadata": {
"accountId": "f9f79265f388666de8122cfb508d7776",
"eventSubscriptionId": "1830c4bb612e43c3af7f4cada31fbf3f",
"eventSchemaVersion": 1,
"eventTimestamp": "2025-05-01T02:48:57.132Z"
}
}在构建被取消时触发。
示例:
{
"type": "cf.workersBuilds.worker.build.canceled",
"source": {
"type": "workersBuilds.worker",
"workerName": "my-worker"
},
"payload": {
"buildUuid": "build-12345678-90ab-cdef-1234-567890abcdef",
"status": "canceled",
"buildOutcome": "canceled",
"createdAt": "2025-05-01T02:48:57.132Z",
"initializingAt": "2025-05-01T02:48:58.132Z",
"runningAt": "2025-05-01T02:48:59.132Z",
"stoppedAt": "2025-05-01T02:49:30.132Z",
"buildTriggerMetadata": {
"buildTriggerSource": "push_event",
"branch": "main",
"commitHash": "abc123def456",
"commitMessage": "Fix bug in authentication",
"author": "[email protected]",
"buildCommand": "npm run build",
"deployCommand": "wrangler deploy",
"rootDirectory": "/",
"repoName": "my-worker-repo",
"providerAccountName": "github-user",
"providerType": "github"
}
},
"metadata": {
"accountId": "f9f79265f388666de8122cfb508d7776",
"eventSubscriptionId": "1830c4bb612e43c3af7f4cada31fbf3f",
"eventSchemaVersion": 1,
"eventTimestamp": "2025-05-01T02:48:57.132Z"
}
}在构建成功时触发。
示例:
{
"type": "cf.workersBuilds.worker.build.succeeded",
"source": {
"type": "workersBuilds.worker",
"workerName": "my-worker"
},
"payload": {
"buildUuid": "build-12345678-90ab-cdef-1234-567890abcdef",
"status": "success",
"buildOutcome": "success",
"createdAt": "2025-05-01T02:48:57.132Z",
"initializingAt": "2025-05-01T02:48:58.132Z",
"runningAt": "2025-05-01T02:48:59.132Z",
"stoppedAt": "2025-05-01T02:50:15.132Z",
"buildTriggerMetadata": {
"buildTriggerSource": "push_event",
"branch": "main",
"commitHash": "abc123def456",
"commitMessage": "Fix bug in authentication",
"author": "[email protected]",
"buildCommand": "npm run build",
"deployCommand": "wrangler deploy",
"rootDirectory": "/",
"repoName": "my-worker-repo",
"providerAccountName": "github-user",
"providerType": "github"
}
},
"metadata": {
"accountId": "f9f79265f388666de8122cfb508d7776",
"eventSubscriptionId": "1830c4bb612e43c3af7f4cada31fbf3f",
"eventSchemaVersion": 1,
"eventTimestamp": "2025-05-01T02:48:57.132Z"
}
}