fix(middle): add middle worker function

This commit is contained in:
Sodesnei 2021-10-09 18:33:42 +08:00
parent 12f594b246
commit 67747a5b6a
3 changed files with 13 additions and 5 deletions

View File

@ -3,7 +3,7 @@ package middle_msg
import "time" import "time"
var ( var (
EventNameLog = "LogContext" EventNameLog = "logcontext"
EventKeyLog = "LogContext" EventKeyLog = "LogContext"
) )

View File

@ -2,15 +2,23 @@ package middle
import ( import (
"context" "context"
msg "gitee.com/timedb/wheatCache/pkg/middle-msg"
) )
func (m *MiddleWare) middleWorker() { func (m *MiddleWare) middleWorker() {
ctx := context.Background() ctx := context.Background()
workEvent := m.eventConsumer.Receive(ctx) workEvent := m.eventConsumer.Receive(ctx)
m.loadPlugins() m.loadPlugins()
for _, singles := range m.plugins { switch workEvent.GetEventName() {
for _, single := range singles { case msg.EventNameLog:
single.Exec(workEvent) for middleMsg, singles := range m.plugins {
if middleMsg == msg.EventNameLog {
for _, single := range singles {
single.Exec(workEvent)
}
}
} }
} }

View File

@ -7,7 +7,7 @@ import (
) )
func TestWorker(t *testing.T) { func TestWorker(t *testing.T) {
event := event.NewEvent("LogContext") event := event.NewEvent("logcontext")
m := NewMiddleWare() m := NewMiddleWare()
m.eventDriver.Put(event) m.eventDriver.Put(event)