(pusher IPusher)
| 30 | } |
| 31 | |
| 32 | func (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 | } |
nothing calls this directly
no test coverage detected