// loop will get all the relevant runners
// and iterate over them, and try to run each
loop will get all the relevant runners
and iterate over them, and try to run each
// loop will get all the relevant runners // and iterate over them and try to run each
func (q *Queue) loop() {
	q.logger.Debug("Getting runners from queue")
	runners, err := getRunners(q.db)
	if err != nil {
		q.logger.Error("cannot get runners", zap.String("exception", err.Error()))
		return
	}
	q.logger.Debug("Found runners from Queue", zap.Int("amount", len(runners)))
	for _, runner := range runners {
		q.logger.Debug("Trying to start runner", zap.String("runner", runner.Name))
		var server api.Server
		query := q.db.Where("active = ? and hostname = ?", false, runner.Hostname)
		if query.First(&server).RecordNotFound() {
			q.logger.Debug("Server is already active", zap.String("runner", runner.Name), zap.String("server", runner.Hostname))
			continue
		}
		for _, s := range runner.Stages {
			if s.InApp != nil {
				var settings inapp.Settings
				if err := inapp.Config(s.InApp.Config, &settings); err != nil {
					q.logger.Error("Failed to decode inapp config", zap.String("exception", err.Error()))
					continue
				}
				s.InApp.Settings = settings
			}
		}
		nms, err := activeLicence(q.db, runner.Nms, runner.Licence, runner.Workers)
		if err != nil {
			q.logger.Debug("Failed to fetch licence from NMS",
				zap.String("runner", runner.Name),
				zap.String("nms", runner.Nms),
				zap.String("licencetype", runner.Licence),
				zap.String("exception", err.Error()),
			)
			continue
		}
		run := q.newRun(runner, &server, nms)
		if err := run.setActive(); err != nil {
			q.logger.Error("Cannot set runner to active", zap.String("exception", err.Error()))
			continue
		}
		q.logger.Info("Starting runner",
			zap.String("runner", runner.Name),
			zap.String("server", runner.Hostname),
			zap.String("nms", runner.Nms),
			zap.String("licence", runner.Licence),
			zap.Int("workers", int(runner.Workers)),
		)
		go run.handle(run.start())
	}
}
func ( q * Queue ) loop ( ) { q . logger . Debug ( " " ) runners , err := getRunners ( q . db ) if err != nil { q . logger . Error ( " " , zap . String ( " " , err . Error ( ) ) ) return } q . logger . Debug ( " " , zap . Int ( " " , len ( runners ) ) ) for _ , runner := range runners { q . logger . Debug ( " " , zap . String ( " " , runner . Name ) ) var server api . Server query := q . db . Where ( " " , false , runner . Hostname ) if query . First ( & server ) . RecordNotFound ( ) { q . logger . Debug ( " " , zap . String ( " " , runner . Name ) , zap . String ( " " , runner . Hostname ) ) continue } for _ , s := range runner . Stages { if s . InApp != nil { var settings inapp . Settings if err := inapp . Config ( s . InApp . Config , & settings ) ; err != nil { q . logger . Error ( " " , zap . String ( " " , err . Error ( ) ) ) continue } s . InApp . Settings = settings } } nms , err := activeLicence ( q . db , runner . Nms , runner . Licence , runner . Workers ) if err != nil { q . logger . Debug ( " " , zap . String ( " " , runner . Name ) , zap . String ( " " , runner . Nms ) , zap . String ( " " , runner . Licence ) , zap . String ( " " , err . Error ( ) ) , ) continue } run := q . newRun ( runner , & server , nms ) if err := run . setActive ( ) ; err != nil { q . logger . Error ( " " , zap . String ( " " , err . Error ( ) ) ) continue } q . logger . Info ( " " , zap . String ( " " , runner . Name ) , zap . String ( " " , runner . Hostname ) , zap . String ( " " , runner . Nms ) , zap . String ( " " , runner . Licence ) , zap . Int ( " " , int ( runner . Workers ) ) , ) go run . handle ( run . start ( ) ) } }
loop will get all the relevant runners
and iterate over them, and try to run each
loop will get all the relevant runners and iterate over them and try to run each
// loop over the runners // check if the runners server is active // Check if the runner has an inApp-stage // Decode the settings for the inApp-stage // FIXME: currently just logging the error - maybe we should return the error(?) //  No neet to set the root directory in the script settings, as it is done in the ruby script. // set the settings to the inApp-stage // Check to see if licence is active // create a new run