func()

in internal/daemon/sqlserver/sqlserver.go [48:85]


func (s *Service) Start(ctx context.Context, a any) {
	// Check if the enabled field is unset. If it is, then the service is still enabled if the workload is present.
	if s.Config.GetSqlserverConfiguration() == nil || s.Config.GetSqlserverConfiguration().Enabled == nil {
		log.CtxLogger(ctx).Info("SQL Server service enabled field is not set, will check for workload presence to determine if service should be enabled.")
		go (func() {
			for {
				s.checkServiceCommunication(ctx)
			}
		})()
		// If the workload is present, proceed with starting the service even if it is not enabled.
		for !s.isProcessPresent {
			time.Sleep(5 * time.Second)
		}
		log.CtxLogger(ctx).Info("SQL Server workload is present. Starting service.")
	} else if !s.Config.GetSqlserverConfiguration().GetEnabled() {
		// If SQL Server workload agent service is explicitly disabled in the configuration, then return.
		log.CtxLogger(ctx).Info("SQL Server workload agent service is disabled in the configuration")
		return
	}

	// Start SQL Server Metric Collection
	mcCtx := log.SetCtx(ctx, "context", "SQLServerMetricCollection")
	metricCollectionRoutine := &recovery.RecoverableRoutine{
		Routine:             runMetricCollection,
		RoutineArg:          runMetricCollectionArgs{s},
		ErrorCode:           usagemetrics.SQLServerMetricCollectionFailure,
		UsageLogger:         *usagemetrics.UsageLogger,
		ExpectedMinDuration: 0,
	}
	metricCollectionRoutine.StartRoutine(mcCtx)
	for {
		select {
		case <-ctx.Done():
			log.CtxLogger(ctx).Info("SQL Server workload agent service cancellation requested")
			return
		}
	}
}