// Beat will check if there is any unhealthy runners
// and set those to timed out
Beat will check if there is any unhealthy runners
and set those to timed out
// Beat will check if there is any unhealthy runners // and set those to timed out
func (s Service) Beat() {
	for {
		var runners []api.Runner
		var lastCheck = time.Now().Add(-s.pause)
		var query = s.db.Where("active = ? AND healthy_at < ?", true, lastCheck)
		if err := query.Find(&runners).Error; err != nil {
			s.logger.Error("Failed to fetch runners", zap.String("exception", err.Error()))
		}
		s.logger.Info("Got unhealthy runners from db", zap.Int("amount", len(runners)))
		for _, runner := range runners {
			runner.Status = avian.StatusTimeout
			runner.Active = false
			if err := s.db.Save(&runner).Error; err != nil {
				s.logger.Error("Cannot save the failed runner", zap.String("exception", err.Error()))
			}
			if err := s.runnersvc.SetServerActivity(runner, false); err != nil {
				s.logger.Error("Cannot save the failed runner", zap.String("exception", err.Error()))
			}
			if err := s.runnersvc.ResetNms(runner); err != nil {
				s.logger.Error("Cannot save the failed runner", zap.String("exception", err.Error()))
			}
			if err := s.runnersvc.RemoveScript(runner); err != nil {
				s.logger.Error("Cannot remove script for runner", zap.String("exception", err.Error()))
			}
		}
		time.Sleep(s.pause)
	}
}
func ( s Service ) Beat ( ) { for { var runners [ ] api . Runner var lastCheck = time . Now ( ) . Add ( - s . pause ) var query = s . db . Where ( " " , true , lastCheck ) if err := query . Find ( & runners ) . Error ; err != nil { s . logger . Error ( " " , zap . String ( " " , err . Error ( ) ) ) } s . logger . Info ( " " , zap . Int ( " " , len ( runners ) ) ) for _ , runner := range runners { runner . Status = avian . StatusTimeout runner . Active = false if err := s . db . Save ( & runner ) . Error ; err != nil { s . logger . Error ( " " , zap . String ( " " , err . Error ( ) ) ) } if err := s . runnersvc . SetServerActivity ( runner , false ) ; err != nil { s . logger . Error ( " " , zap . String ( " " , err . Error ( ) ) ) } if err := s . runnersvc . ResetNms ( runner ) ; err != nil { s . logger . Error ( " " , zap . String ( " " , err . Error ( ) ) ) } if err := s . runnersvc . RemoveScript ( runner ) ; err != nil { s . logger . Error ( " " , zap . String ( " " , err . Error ( ) ) ) } } time . Sleep ( s . pause ) } }
Beat will check if there is any unhealthy runners
and set those to timed out
Beat will check if there is any unhealthy runners and set those to timed out
// get the unhealthy runners // iterate over the unhealthy runnres // set status to timeout and active to false // Set servers activity // update nms information // remove the script from the remote machine