MCPcopy
hub / github.com/crowdsecurity/crowdsec / trySubscribeEvents

Method trySubscribeEvents

pkg/acquisition/modules/docker/run.go:352–376  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

350}
351
352func (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.

Callers 1

subscribeEventsMethod · 0.95

Calls 1

EventsMethod · 0.80

Tested by

no test coverage detected