MCPcopy
hub / github.com/docker/compose / Events

Method Events

pkg/compose/events.go:30–81  ·  view source on GitHub ↗
(ctx context.Context, projectName string, options api.EventsOptions)

Source from the content-addressed store, hash-verified

28)
29
30func (s *composeService) Events(ctx context.Context, projectName string, options api.EventsOptions) error {
31 projectName = strings.ToLower(projectName)
32 res := s.apiClient().Events(ctx, client.EventsListOptions{
33 Filters: projectFilter(projectName),
34 Since: options.Since,
35 Until: options.Until,
36 })
37 for {
38 select {
39 case event := <-res.Messages:
40 // TODO: support other event types
41 if event.Type != "container" {
42 continue
43 }
44
45 if event.Actor.Attributes[api.OneoffLabel] == "True" {
46 // ignore
47 continue
48 }
49 service := event.Actor.Attributes[api.ServiceLabel]
50 if len(options.Services) > 0 && !slices.Contains(options.Services, service) {
51 continue
52 }
53
54 attributes := map[string]string{}
55 for k, v := range event.Actor.Attributes {
56 if strings.HasPrefix(k, "com.docker.compose.") {
57 continue
58 }
59 attributes[k] = v
60 }
61
62 timestamp := time.Unix(event.Time, 0)
63 if event.TimeNano != 0 {
64 timestamp = time.Unix(0, event.TimeNano)
65 }
66 err := options.Consumer(api.Event{
67 Timestamp: timestamp,
68 Service: service,
69 Container: event.Actor.ID,
70 Status: string(event.Action),
71 Attributes: attributes,
72 })
73 if err != nil {
74 return err
75 }
76
77 case err := <-res.Err:
78 return err
79 }
80 }
81}

Callers

nothing calls this directly

Calls 3

apiClientMethod · 0.95
projectFilterFunction · 0.85
EventsMethod · 0.65

Tested by

no test coverage detected