| 350 | } |
| 351 | |
| 352 | func (d *Source) trySubscribeEvents(ctx context.Context) (*subscription, error) { |
| 353 | filters := client.Filters{ |
| 354 | "type": { |
| 355 | "container": true, |
| 356 | "service": d.isSwarmManager, |
| 357 | }, |
| 358 | } |
| 359 | |
| 360 | opts := client.EventsListOptions{ |
| 361 | Filters: filters, |
| 362 | } |
| 363 | |
| 364 | result := d.Client.Events(ctx, opts) |
| 365 | |
| 366 | // Is there an immediate error (proxy/daemon unavailable) ? |
| 367 | select { |
| 368 | case err := <-result.Err: |
| 369 | if err != nil { |
| 370 | return nil, fmt.Errorf("docker events connection failed: %w", err) |
| 371 | } |
| 372 | default: |
| 373 | } |
| 374 | |
| 375 | return &subscription{events: result.Messages, errs: result.Err}, nil |
| 376 | } |
| 377 | |
| 378 | // subscribeEvents will loop until it can successfully call d.Client.Events() |
| 379 | // without immediately receiving an error. It applies exponential backoff on failures. |