Proposal: 领域事件、通知与 Webhook

未关闭
#7 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃

调研方向

Read the overall proposal in #1 and the implementation issue #16 first. This issue defines the event contract and staged requirements for synchronous subscribers, notifications, email, and later outbox and webhook work, but names no source files or tests. Before implementation, identify which P0 requirements #16 covers; done means the P0 contract is frozen as described here, with webhook delivery left for P1.

由索引模型根据 Issue 内容生成。

描述

proposal

背景

总体方案见 #1。领域事件是平台的核心扩展点:站内通知、邮件、未来的 webhook 与自动化规则都是订阅者。事件契约一旦发布即对外承诺:字段只增不改语义。

事件结构

{
  "topic": "ticket.state_changed",
  "event_id": "0192f0aa-6c4e-7abe-9c1e-3f2a91d0ab12",
  "tenant_id": 1,
  "happened_at": "2026-11-14T10:30:00Z",
  "payload": { }
}

字段命名 snake_case;event_id 供消费方幂等去重。

领域事件(P0 集)

topic 触发时机 payload 关键字段
ticket.created 工单创建 ticket_id, number, type, title, creator_id
ticket.assigned 分派 / 转交 ticket_id, assignee_id, operator_id
ticket.state_changed 状态流转 ticket_id, from, to, action, operator_id
ticket.commented 回复(含内部备注) ticket_id, comment_id, author_id, is_internal
ticket.attachment_added 附件上传 ticket_id, attachment_id, filename

P0:同步分发

业务 service 在事务提交后调用 events.Publish(ctx, event):

  • 订阅者 1:站内通知(写 notifications 表);
  • 订阅者 2:邮件(SMTP 已配置时发送;发送失败仅记 error 日志,不影响主流程);
  • 订阅者执行 panic 隔离(recover + error 日志),订阅者失败不回滚业务事务、不阻断其他订阅者。

P0 接收人规则:

topic 接收人
ticket.created 全部 agent 与 tenant_admin(P0 无自动分派)
ticket.assigned 被分派人
ticket.state_changed 创建者 + 当前处理人(排除操作者本人)
ticket.commented 创建者 + 当前处理人(排除作者本人)

P1:outbox + webhook

  • events 表作为 outbox:业务事务内写事件行,后台 worker 轮询投递,至少一次语义;
  • webhook_endpoints:URL + secret + 订阅 topics;投递头 X-TickFlow-Signature: sha256=<hmac(secret, timestamp + body)> 与时间戳防重放;失败指数退避重试,连续失败标记不健康并告警;
  • 消费方以 event_id 做幂等。

通知偏好与多通道(企业微信 / 钉钉)

P2。代码上保留订阅者抽象即可,不预置半成品配置项。

Expect

  • P0 事件契约随本文冻结,#16 据此实现站内 + 邮件;
  • webhook 属 P1,本文只锁定契约方向,不在 P0 实现任何投递代码。
主要语言
没有语言数据
星标
0
派生
1
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

LinuxSuRen/tick-flow 的其他 Issue

查看 LinuxSuRen/tick-flow 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。