mirror of
https://github.com/Monibuca/engine.git
synced 2025-10-07 09:30:56 +08:00
fix: avoid report block evenbus
This commit is contained in:
22
main.go
22
main.go
@@ -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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user