func()

in internal/servicecommunication/datawarehouseactivation/datawarehouseactivation.go [109:145]


func (s Service) DataWarehouseActivationCheck(ctx context.Context, a any) {
	currentStatus := notYetChecked
	log.CtxLogger(ctx).Info("DataWarehouseActivationCheck started")
	var chs []chan<- *servicecommunication.Message
	var ok bool
	if chs, ok = a.([]chan<- *servicecommunication.Message); !ok {
		log.CtxLogger(ctx).Warn("args is not of type chan servicecommunication.Message")
		return
	}
	frequency := 5 * time.Minute
	ticker := time.NewTicker(frequency)
	defer ticker.Stop()
	for {
		result, statusChanged := s.dwActivationLoop(ctx, currentStatus)
		// If the status has changed, send the new information across the channels.
		if statusChanged {
			currentStatus = notActivated
			if result.Activated {
				currentStatus = activated
			}
			s.sendActivationResult(ctx, chs, result)
		}

		// We can stop checking if the data warehouse is activated once we know that it is.
		if result.Activated {
			return
		}
		select {
		case <-ctx.Done():
			log.CtxLogger(ctx).Info("DataWarehouseActivationCheck cancellation requested")
			return
		case <-ticker.C:
			log.CtxLogger(ctx).Debug("DataWarehouseActivationCheck ticker fired")
			continue
		}
	}
}