fix: avoid report block evenbus

This commit is contained in:
langhuihui
2023-10-19 15:32:58 +08:00
parent 3668db0eb6
commit 6e1ee72efe

22
main.go
View File

@@ -146,7 +146,7 @@ func Run(ctx context.Context, conf any) (err error) {
plugin.assign() plugin.assign()
} }
UUID := uuid.NewString() UUID := uuid.NewString()
reportTimer := time.NewTicker(time.Minute)
contentBuf := bytes.NewBuffer(nil) contentBuf := bytes.NewBuffer(nil)
req, _ := http.NewRequestWithContext(ctx, http.MethodPost, "https://console.monibuca.com/report", nil) req, _ := http.NewRequestWithContext(ctx, http.MethodPost, "https://console.monibuca.com/report", nil)
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
@@ -212,8 +212,19 @@ func Run(ctx context.Context, conf any) (err error) {
if EngineConfig.Secret != "" { if EngineConfig.Secret != "" {
EngineConfig.OnEvent(ctx) EngineConfig.OnEvent(ctx)
} }
var c http.Client go func() {
c.Do(req) var c http.Client
reportTimer := time.NewTimer(time.Minute)
c.Do(req)
for {
<-reportTimer.C
contentBuf.Reset()
contentBuf.WriteString(fmt.Sprintf(`{"uuid":"`+UUID+`","streams":%d}`, Streams.Len()))
req.Body = io.NopCloser(contentBuf)
c.Do(req)
reportTimer.Reset(time.Minute)
}
}()
for _, plugin := range enabledPlugins { for _, plugin := range enabledPlugins {
plugin.Config.OnEvent(EngineConfig) //引擎初始化完成后,通知插件 plugin.Config.OnEvent(EngineConfig) //引擎初始化完成后,通知插件
} }
@@ -234,11 +245,6 @@ func Run(ctx context.Context, conf any) (err error) {
} }
case <-ctx.Done(): case <-ctx.Done():
return return
case <-reportTimer.C:
contentBuf.Reset()
contentBuf.WriteString(fmt.Sprintf(`{"uuid":"`+UUID+`","streams":%d}`, Streams.Len()))
req.Body = io.NopCloser(contentBuf)
c.Do(req)
} }
} }
} }