MCPcopy Index your code
hub / github.com/Monibuca/engine / startPush

Method startPush

pusher.go:32–79  ·  view source on GitHub ↗
(pusher IPusher)

Source from the content-addressed store, hash-verified

30}
31
32func (pub *Pusher) startPush(pusher IPusher) {
33 badPusher := true
34 var err error
35 key := pub.RemoteURL
36
37 if oldPusher, loaded := Pushers.LoadOrStore(key, pusher); loaded {
38 sub := oldPusher.(IPusher).GetSubscriber()
39 pusher.Error("pusher already exists", zap.Time("createAt", sub.StartTime))
40 return
41 }
42
43 defer Pushers.Delete(key)
44 defer pusher.Disconnect()
45 var startTime time.Time
46 for pusher.Info("start push"); pusher.Reconnect(); pusher.Warn("restart push") {
47 if time.Since(startTime) < 5*time.Second {
48 time.Sleep(5 * time.Second)
49 }
50 startTime = time.Now()
51 if err = pusher.Subscribe(pub.StreamPath, pusher); err != nil {
52 pusher.Error("push subscribe", zap.Error(err))
53 } else {
54 stream := pusher.GetSubscriber().Stream
55 if err = pusher.Connect(); err != nil {
56 if err == io.EOF {
57 pusher.Info("push complete")
58 return
59 }
60 pusher.Error("push connect", zap.Error(err))
61 time.Sleep(time.Second * 5)
62 stream.Receive(Unsubscribe(pusher)) // 通知stream移除订阅者
63 if badPusher {
64 return
65 }
66 } else if err = pusher.Push(); err != nil && !stream.IsClosed() {
67 pusher.Error("push", zap.Error(err))
68 pusher.Stop()
69 }
70 badPusher = false
71 if stream.IsClosed() {
72 pusher.Info("stop push closed")
73 return
74 }
75 }
76 pusher.Disconnect()
77 }
78 pusher.Warn("stop push stop reconnect")
79}

Callers

nothing calls this directly

Calls 14

UnsubscribeTypeAlias · 0.85
GetSubscriberMethod · 0.65
ErrorMethod · 0.65
DisconnectMethod · 0.65
InfoMethod · 0.65
ReconnectMethod · 0.65
WarnMethod · 0.65
SubscribeMethod · 0.65
ConnectMethod · 0.65
ReceiveMethod · 0.65
PushMethod · 0.65
IsClosedMethod · 0.65

Tested by

no test coverage detected