// Run starts running Handler until the given context has done.
Run starts running Handler until the given context has done.
// Run starts running Handler until the given context has done .
func (h *Handler) Run(ctx context.Context) error {
	h.logger.Info("start running planpreview handler")
	startWorker := func(ctx context.Context, cmdCh <-chan model.ReportableCommand) {
		h.logger.Info("started a worker for handling plan-preview command")
		for {
			select {
			case cmd := <-cmdCh:
				h.handleCommand(ctx, cmd)
			case <-ctx.Done():
				h.logger.Info("a worker has been stopped")
				return
			}
		}
	}
	h.logger.Info(fmt.Sprintf("spawn %d worker to handle commands", h.options.workerNum))
	for i := 0; i < h.options.workerNum; i++ {
		go startWorker(ctx, h.commandCh)
	}
	commandTicker := time.NewTicker(h.options.commandCheckInterval)
	defer commandTicker.Stop()
L:
	for {
		select {
		case <-ctx.Done():
			break L
		case <-commandTicker.C:
			h.enqueueNewCommands(ctx)
		}
	}
	h.logger.Info("planpreview handler has been stopped")
	return nil
}
func ( h * Handler ) Run ( ctx context . Context ) error { h . logger . Info ( " " ) startWorker := func ( ctx context . Context , cmdCh <- chan model . ReportableCommand ) { h . logger . Info ( " " ) for { select { case cmd := <- cmdCh : h . handleCommand ( ctx , cmd ) case <- ctx . Done ( ) : h . logger . Info ( " " ) return } } } h . logger . Info ( fmt . Sprintf ( " " , h . options . workerNum ) ) for i := 0 ; i < h . options . workerNum ; i ++ { go startWorker ( ctx , h . commandCh ) } commandTicker := time . NewTicker ( h . options . commandCheckInterval ) defer commandTicker . Stop ( ) L : for { select { case <- ctx . Done ( ) : break L case <- commandTicker . C : h . enqueueNewCommands ( ctx ) } } h . logger . Info ( " " ) return nil }
Run starts running Handler until the given context has done.
Run starts running Handler until the given context has done .