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)
| 120 | // statistics and distribute jobs into any listening subscriber channels. |
| 121 | // (Subscriber channels are non-blocking so this should be quite fast.) |
| 122 | func (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 | // |
no test coverage detected