MCPcopy Create free account
hub / github.com/riverqueue/river / distributeJobUpdates

Method distributeJobUpdates

subscription_manager.go:122–147  ·  view source on GitHub ↗

Receives updates from the completer and prompts the client to update statistics and distribute jobs into any listening subscriber channels. (Subscriber channels are non-blocking so this should be quite fast.)

(ctx context.Context, updates []jobcompleter.CompleterJobUpdated)

Source from the content-addressed store, hash-verified

120// statistics and distribute jobs into any listening subscriber channels.
121// (Subscriber channels are non-blocking so this should be quite fast.)
122func (sm *subscriptionManager) distributeJobUpdates(ctx context.Context, updates []jobcompleter.CompleterJobUpdated) {
123 func() {
124 sm.statsMu.Lock()
125 defer sm.statsMu.Unlock()
126
127 for _, update := range updates {
128 stats := update.JobStats
129 sm.statsAggregate.CompleteDuration += stats.CompleteDuration
130 sm.statsAggregate.QueueWaitDuration += stats.QueueWaitDuration
131 sm.statsAggregate.RunDuration += stats.RunDuration
132 sm.statsNumJobs++
133 }
134 }()
135
136 sm.mu.Lock()
137 defer sm.mu.Unlock()
138
139 // Quick path so we don't need to allocate anything if no one is listening.
140 if len(sm.subscriptions) < 1 {
141 return
142 }
143
144 for _, update := range updates {
145 sm.distributeJobEvent(ctx, update.Job, jobStatisticsFromInternal(update.JobStats), update.Snoozed)
146 }
147}
148
149// Distribute a single event into any listening subscriber channels.
150//

Callers 1

StartMethod · 0.95

Calls 2

distributeJobEventMethod · 0.95

Tested by

no test coverage detected