()
| 130 | } |
| 131 | |
| 132 | func (c *Controller) Start() error { |
| 133 | c.mux.Lock() |
| 134 | defer c.mux.Unlock() |
| 135 | |
| 136 | if c.running { |
| 137 | return nil |
| 138 | } |
| 139 | c.quit = nil |
| 140 | |
| 141 | c.loadAllEnterprises() |
| 142 | c.loadAllOrganizations() |
| 143 | c.loadAllRepositories() |
| 144 | |
| 145 | consumer, err := watcher.RegisterConsumer( |
| 146 | c.ctx, c.consumerID, |
| 147 | composeControllerWatcherFilters(), |
| 148 | ) |
| 149 | if err != nil { |
| 150 | return fmt.Errorf("failed to create consumer for entity controller: %w", err) |
| 151 | } |
| 152 | |
| 153 | c.consumer = consumer |
| 154 | c.running = true |
| 155 | c.quit = make(chan struct{}) |
| 156 | c.eventQueue = workersCommon.NewUnboundedChan[dbCommon.ChangePayload](c.ctx, c.quit) |
| 157 | |
| 158 | go c.loop() |
| 159 | go c.eventQueue.Process(c.handleWatcherEvent) |
| 160 | go workersCommon.RetryLoop(c.ctx, c.quit, retryLoopInterval, c.retryFailedWorkers) |
| 161 | |
| 162 | return nil |
| 163 | } |
| 164 | |
| 165 | func (c *Controller) Stop() error { |
| 166 | slog.DebugContext(c.ctx, "stopping entity controller", "entity", c.consumerID) |
no test coverage detected