topfans/backend/services/statisticService/sink/event_sink.go
zerosaturation bed8f8e578 feat(statistic): T4-T8 event collection framework (Event + Sink + Repo + Service + Workers)
- Event model + ToJSON
- EventSink interface + ChannelEventSink (non-blocking Submit)
- event_repo: batch INSERT ON CONFLICT DO NOTHING dedup
- event_service: 7-type whitelist + 1KB props limit + ReceivedAt auto-fill
- event_flusher: 100/1s batch + sync metric_recent_level_ups on level_up
- metric_weekly + metric_upcoming workers (5min/15min with pg_try_advisory_lock)
- partitioner: 7-day pre-create + 30-day cleanup (00:05 create / 00:30 cleanup)
- 22 unit + integration tests (model/repo/service/sink/worker)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-08 17:20:53 +08:00

20 lines
600 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package sink
import (
"context"
"github.com/topfans/backend/services/statisticService/model"
)
// EventSink 事件 sink 接口
// 本期实现: ChannelEventSink推到 channel由 event_flusher 消费)
// 未来扩展: KafkaEventSink / ClickHouseDualWriteSink / SamplingEventSink
type EventSink interface {
// Submit 提交单个事件非阻塞channel 满时返回 ErrChannelFull
Submit(ctx context.Context, e *model.Event) error
// SubmitBatch 批量提交;任一失败即停止
SubmitBatch(ctx context.Context, es []*model.Event) error
// Close 关闭 sink
Close() error
}