forked from p93542168/wheat-cache
fix(middle): add middle worker function
This commit is contained in:
parent
12f594b246
commit
67747a5b6a
|
@ -3,7 +3,7 @@ package middle_msg
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
EventNameLog = "LogContext"
|
EventNameLog = "logcontext"
|
||||||
|
|
||||||
EventKeyLog = "LogContext"
|
EventKeyLog = "LogContext"
|
||||||
)
|
)
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue