eventbus

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel string

Channel 标识一条实时推送通道(如 "task:123")。

func TaskChannel

func TaskChannel(taskID int64) Channel

TaskChannel 返回某个任务的实时事件通道。

type EventBus

type EventBus struct {
	// contains filtered or unexported fields
}

EventBus — AI Engine Event Infrastructure V2

事件分层路由:

  • Transient → WS only(不入库,不 replay,丢失没关系)
  • Persistent → DB + WS + Sequence(状态恢复、Timeline 重建)
  • Audit → DB only(不推送 WS)

Phase 2 roadmap:

  • timeline_patch: PatchImportance tiers (structural/visual/ephemeral), only structural persists
  • Client: Snapshot + Incremental Events instead of full replay
  • inferGrade: remove fallback, all emitters set Grade explicitly

func NewEventBus

func NewEventBus(
	repo repository.EventRepository,
	pub Publisher,
) *EventBus

func (*EventBus) Publish

func (b *EventBus) Publish(taskID int64, event *domain.TaskEvent)

Publish 按事件等级分流:

  • Transient: 仅 push WS
  • Persistent: 写 DB(分配 sequence)+ push WS
  • Audit: 仅写 DB

如果 event.Grade 为空,则通过 inferGrade 自动推断。

func (*EventBus) PublishToChannel

func (b *EventBus) PublishToChannel(ch Channel, event *domain.TaskEvent)

PublishToChannel 直接向指定 WS channel 推送事件,不写 DB。 专用于回放等只需 WS 输出的场景。

func (*EventBus) Subscribe

func (b *EventBus) Subscribe(eventType string) <-chan *domain.TaskEvent

func (*EventBus) Unsubscribe

func (b *EventBus) Unsubscribe(eventType string, ch <-chan *domain.TaskEvent)

Unsubscribe 摘除订阅并关闭 channel,令消费方的 range 循环退出。 对未订阅的 channel 调用是安全的 no-op。

type Publisher

type Publisher interface {
	Publish(ch Channel, event any)
}

Publisher 是实时事件推送的传输抽象。EventBus 只依赖此接口, 具体实现(WebSocket、SSE、日志等)由业务侧注入。传输层实现只需 提供一个 Publish 方法即可满足该接口。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL