| 43 | } |
| 44 | |
| 45 | func (m *QueueMaintainer) Start(ctx context.Context) error { |
| 46 | ctx, shouldStart, started, stopped := m.StartInit(ctx) |
| 47 | if !shouldStart { |
| 48 | return nil |
| 49 | } |
| 50 | |
| 51 | for _, service := range m.servicesByName { |
| 52 | if err := service.Start(ctx); err != nil { |
| 53 | startstop.StopAllParallel(maputil.Values(m.servicesByName)...) |
| 54 | stopped() |
| 55 | return err |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | go func() { |
| 60 | // Wait for all subservices to start up before signaling our own start. |
| 61 | startstop.WaitAllStarted(maputil.Values(m.servicesByName)...) |
| 62 | |
| 63 | started() |
| 64 | defer stopped() // this defer should come first so it's last out |
| 65 | |
| 66 | <-ctx.Done() |
| 67 | |
| 68 | startstop.StopAllParallel(maputil.Values(m.servicesByName)...) |
| 69 | }() |
| 70 | |
| 71 | return nil |
| 72 | } |
| 73 | |
| 74 | // GetService is a convenience method for getting a service by name and casting |
| 75 | // it to the desired type. It should only be used in tests due to its use of |