MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / StartPushDispatch

Method StartPushDispatch

internal/server/push_dispatch.go:224–269  ·  view source on GitHub ↗

StartPushDispatch starts the dispatch loop. Idempotent; tracked on s.bg.

()

Source from the content-addressed store, hash-verified

222
223// StartPushDispatch starts the dispatch loop. Idempotent; tracked on s.bg.
224func (s *Server) StartPushDispatch() {
225 cfg := s.resolvePushDispatchSettings()
226 d := &s.pushDispatch
227 d.mu.Lock()
228 if d.running {
229 d.mu.Unlock()
230 return
231 }
232 d.stop = make(chan struct{})
233 d.running = true
234 stop, tick := d.stop, d.tick
235 d.startedInterval = cfg.interval
236 d.mu.Unlock()
237
238 s.bg.Add(1)
239 go func() {
240 defer s.bg.Done()
241 defer s.recoverSweeper("push-dispatch")
242 // A stop cancels the tick in flight, which unclaims what it holds.
243 ctx, cancel := context.WithCancel(context.Background())
244 defer cancel()
245 go func() {
246 select {
247 case <-stop:
248 cancel()
249 case <-ctx.Done():
250 }
251 }()
252 var c <-chan time.Time
253 if tick != nil {
254 c = tick
255 } else {
256 t := time.NewTicker(cfg.interval)
257 defer t.Stop()
258 c = t.C
259 }
260 for {
261 select {
262 case <-stop:
263 return
264 case <-c:
265 s.runPushDispatchTick(ctx)
266 }
267 }
268 }()
269}
270
271// PushDispatchRunning reports whether the dispatch loop has been started and
272// not stopped. Read-only; startup's wiring test reads it (TASK-3939 B2c).

Calls 10

recoverSweeperMethod · 0.95
runPushDispatchTickMethod · 0.95
LockMethod · 0.80
UnlockMethod · 0.80
DoneMethod · 0.80
AddMethod · 0.65
makeFunction · 0.50
cancelFunction · 0.50
StopMethod · 0.45