Initial commit: Pipeline Database
This commit is contained in:
72
examples/common/handler.go
Normal file
72
examples/common/handler.go
Normal file
@@ -0,0 +1,72 @@
|
||||
// 通用示例处理器
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
// ExampleHandler 示例外部处理器
|
||||
type ExampleHandler struct {
|
||||
name string
|
||||
}
|
||||
|
||||
// NewExampleHandler 创建示例处理器
|
||||
func NewExampleHandler(name string) *ExampleHandler {
|
||||
return &ExampleHandler{
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
// WillWarm 热数据预热处理
|
||||
func (h *ExampleHandler) WillWarm(ctx context.Context, group string, data []byte) ([]byte, error) {
|
||||
log.Printf("🔥 [%s] 预热处理, 组=%s, 数据大小=%d bytes", h.name, group, len(data))
|
||||
|
||||
// 示例:可以在这里进行数据预处理、验证、转换等
|
||||
// 这里简单返回原数据
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// WillCold 温数据冷却处理
|
||||
func (h *ExampleHandler) WillCold(ctx context.Context, group string, data []byte) ([]byte, error) {
|
||||
log.Printf("❄️ [%s] 冷却处理, 组=%s, 数据大小=%d bytes", h.name, group, len(data))
|
||||
|
||||
// 示例:可以在这里进行数据压缩、归档、清理等
|
||||
// 这里简单返回原数据
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// OnComplete 组完成回调
|
||||
func (h *ExampleHandler) OnComplete(ctx context.Context, group string) error {
|
||||
log.Printf("🎉 [%s] 组完成回调, 组=%s - 所有数据已处理完成", h.name, group)
|
||||
|
||||
// 示例:可以在这里进行组级别的清理、通知、统计等
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoggingHandler 简单的日志处理器(用于不需要复杂处理的示例)
|
||||
type LoggingHandler struct{}
|
||||
|
||||
// NewLoggingHandler 创建日志处理器
|
||||
func NewLoggingHandler() *LoggingHandler {
|
||||
return &LoggingHandler{}
|
||||
}
|
||||
|
||||
// WillWarm 热数据预热处理
|
||||
func (h *LoggingHandler) WillWarm(ctx context.Context, group string, data []byte) ([]byte, error) {
|
||||
fmt.Printf("🔥 数据预热: 组[%s] %d bytes\n", group, len(data))
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// WillCold 温数据冷却处理
|
||||
func (h *LoggingHandler) WillCold(ctx context.Context, group string, data []byte) ([]byte, error) {
|
||||
fmt.Printf("❄️ 数据冷却: 组[%s] %d bytes\n", group, len(data))
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// OnComplete 组完成回调
|
||||
func (h *LoggingHandler) OnComplete(ctx context.Context, group string) error {
|
||||
fmt.Printf("✅ 组完成: [%s]\n", group)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user