watch ranges over the passed in event chan and processes the events based on the handlers created for a given action. To stop watching, close the event chan.
(ctx context.Context, c <-chan events.Message)
| 384 | // handlers created for a given action. |
| 385 | // To stop watching, close the event chan. |
| 386 | func (eh *eventHandler) watch(ctx context.Context, c <-chan events.Message) { |
| 387 | for e := range c { |
| 388 | h, exists := eh.handlers[e.Action] |
| 389 | if !exists { |
| 390 | continue |
| 391 | } |
| 392 | if e.Actor.ID == "" { |
| 393 | log.G(ctx).WithField("event", e).Errorf("event handler: received %s event with empty ID", e.Action) |
| 394 | continue |
| 395 | } |
| 396 | logger := log.G(ctx).WithFields(log.Fields{ |
| 397 | "event": e.Action, |
| 398 | "container": e.Actor.ID, |
| 399 | }) |
| 400 | |
| 401 | go h(log.WithLogger(ctx, logger), e) |
| 402 | } |
| 403 | } |