fix: repush

This commit is contained in:
langhuihui
2023-12-07 16:32:14 +08:00
parent 48d6e277e4
commit 8ee68a7ff7

View File

@@ -7,6 +7,7 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"m7s.live/engine/v4/config" "m7s.live/engine/v4/config"
) )
type IPusher interface { type IPusher interface {
ISubscriber ISubscriber
Push() error Push() error
@@ -31,8 +32,15 @@ func (pub *Pusher) Reconnect() (result bool) {
func (pub *Pusher) startPush(pusher IPusher) { func (pub *Pusher) startPush(pusher IPusher) {
badPusher := true badPusher := true
var err error var err error
Pushers.Store(pub.RemoteURL, pusher) key := pub.RemoteURL
defer Pushers.Delete(pub.RemoteURL)
if oldPusher, loaded := Pushers.LoadOrStore(key, pusher); loaded {
sub := oldPusher.(IPusher).GetSubscriber()
pusher.Error("pusher already exists", zap.Time("createAt", sub.StartTime))
return
}
defer Pushers.Delete(key)
defer pusher.Disconnect() defer pusher.Disconnect()
var startTime time.Time var startTime time.Time
for pusher.Info("start push"); pusher.Reconnect(); pusher.Warn("restart push") { for pusher.Info("start push"); pusher.Reconnect(); pusher.Warn("restart push") {