captureEvent 内部方法:捕获事件
(event *logic.Event)
| 335 | |
| 336 | // captureEvent 内部方法:捕获事件 |
| 337 | func (m *LogicMemoryMiddleware) captureEvent(event *logic.Event) { |
| 338 | if !m.config.EnableCapture { |
| 339 | return |
| 340 | } |
| 341 | |
| 342 | if m.config.AsyncCapture && m.eventBuffer != nil { |
| 343 | // 异步捕获:发送到缓冲区 |
| 344 | select { |
| 345 | case m.eventBuffer <- event: |
| 346 | // 成功放入缓冲区 |
| 347 | default: |
| 348 | // 缓冲区满,丢弃事件(记录警告) |
| 349 | lmLog.Warn(context.Background(), "event buffer full, dropping event", map[string]any{"type": event.Type}) |
| 350 | } |
| 351 | } else { |
| 352 | // 同步捕获:直接处理 |
| 353 | if err := m.manager.ProcessEvent(context.Background(), *event); err != nil { |
| 354 | lmLog.Error(context.Background(), "failed to process event", map[string]any{"error": err.Error()}) |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | // processEventsAsync 异步处理事件的 goroutine |
| 360 | func (m *LogicMemoryMiddleware) processEventsAsync() { |
no test coverage detected