// Delete the specified runner from the db
Delete the specified runner from the db
// Delete the specified runner from the db
func (s RunnerService) Delete(ctx context.Context, r api.RunnerDeleteRequest) (*api.RunnerDeleteResponse, error) {
	s.logger.Debug("Getting runner to delete", zap.String("runner", r.Name))
	tx := s.DB.Begin()
	var runner api.Runner
	err := tx.Preload("Switches").
		Preload("Stages.Process").
		Preload("Stages.SearchAndTag").
		Preload("Stages.Exclude").
		Preload("Stages.Ocr").
		Preload("Stages.Reload").
		Preload("Stages.Populate").
		Preload("Stages.InApp").
		Preload("Stages.SyncDescendants").
		Preload("Stages.ScanNewChildItems").
		Preload("CaseSettings.Case.ElasticSearch").
		Preload("CaseSettings.CompoundCase").
		Preload("CaseSettings.ReviewCompound").
		First(&runner, "name = ? OR id = ?", r.Name, r.Name).Error
	if err != nil {
		tx.Rollback()
		s.logger.Error("Cannot get runner", zap.String("runner", r.Name), zap.String("exception", err.Error()))
		return nil, err
	}
	if runner.Active {
		if !r.Force {
			tx.Rollback()
			s.logger.Error("Cannot delete active runner", zap.String("runner", r.Name))
			return nil, fmt.Errorf("Cannot delete active runner - use force argument")
		}
		if err := tx.Model(&api.Server{}).Where("hostname = ?", runner.Hostname).Update("active", false).Error; err != nil {
			tx.Rollback()
			s.logger.Error("Cannot set server to inactive",
				zap.String("runner", r.Name),
				zap.String("server", runner.Hostname),
				zap.String("exception", err.Error()),
			)
			return nil, fmt.Errorf("Cannot set the active server to inactive: %v", err)
		}
	}
	s.logger.Debug("Deleting runner", zap.String("runner", r.Name))
	if err := tx.Delete(&runner).Error; err != nil {
		tx.Rollback()
		s.logger.Error("Cannot delete runner", zap.String("runner", r.Name), zap.String("exception", err.Error()))
		return nil, err
	}
	if err := tx.Model(&runner).Association("Stages").Delete(runner.Stages).Error; err != nil {
		tx.Rollback()
		s.logger.Error("Cannot delete runner", zap.String("runner", r.Name), zap.String("exception", err.Error()))
		return nil, err
	}
	if err := tx.Model(&runner).Association("Switches").Delete(runner.Switches).Error; err != nil {
		tx.Rollback()
		s.logger.Error("Cannot delete runner", zap.String("runner", r.Name), zap.String("exception", err.Error()))
		return nil, err
	}
	if err := tx.Model(&runner).Association("CaseSettings").Delete(runner.CaseSettings).Error; err != nil {
		tx.Rollback()
		s.logger.Error("Cannot delete runner", zap.String("runner", r.Name), zap.String("exception", err.Error()))
		return nil, err
	}
	if err := tx.Commit().Error; err != nil {
		tx.Rollback()
		s.logger.Error("Cannot delete runner, failed to commit transaction", zap.String("runner", r.Name), zap.String("exception", err.Error()))
		return nil, err
	}
	return &api.RunnerDeleteResponse{}, nil
}
func ( s RunnerService ) Delete ( ctx context . Context , r api . RunnerDeleteRequest ) ( * api . RunnerDeleteResponse , error ) { s . logger . Debug ( " " , zap . String ( " " , r . Name ) ) tx := s . DB . Begin ( ) var runner api . Runner err := tx . Preload ( " " ) . Preload ( " " ) . Preload ( " " ) . Preload ( " " ) . Preload ( " " ) . Preload ( " " ) . Preload ( " " ) . Preload ( " " ) . Preload ( " " ) . Preload ( " " ) . Preload ( " " ) . Preload ( " " ) . Preload ( " " ) . First ( & runner , " " , r . Name , r . Name ) . Error if err != nil { tx . Rollback ( ) s . logger . Error ( " " , zap . String ( " " , r . Name ) , zap . String ( " " , err . Error ( ) ) ) return nil , err } if runner . Active { if ! r . Force { tx . Rollback ( ) s . logger . Error ( " " , zap . String ( " " , r . Name ) ) return nil , fmt . Errorf ( " " ) } if err := tx . Model ( & api . Server { } ) . Where ( " " , runner . Hostname ) . Update ( " " , false ) . Error ; err != nil { tx . Rollback ( ) s . logger . Error ( " " , zap . String ( " " , r . Name ) , zap . String ( " " , runner . Hostname ) , zap . String ( " " , err . Error ( ) ) , ) return nil , fmt . Errorf ( " " , err ) } } s . logger . Debug ( " " , zap . String ( " " , r . Name ) ) if err := tx . Delete ( & runner ) . Error ; err != nil { tx . Rollback ( ) s . logger . Error ( " " , zap . String ( " " , r . Name ) , zap . String ( " " , err . Error ( ) ) ) return nil , err } if err := tx . Model ( & runner ) . Association ( " " ) . Delete ( runner . Stages ) . Error ; err != nil { tx . Rollback ( ) s . logger . Error ( " " , zap . String ( " " , r . Name ) , zap . String ( " " , err . Error ( ) ) ) return nil , err } if err := tx . Model ( & runner ) . Association ( " " ) . Delete ( runner . Switches ) . Error ; err != nil { tx . Rollback ( ) s . logger . Error ( " " , zap . String ( " " , r . Name ) , zap . String ( " " , err . Error ( ) ) ) return nil , err } if err := tx . Model ( & runner ) . Association ( " " ) . Delete ( runner . CaseSettings ) . Error ; err != nil { tx . Rollback ( ) s . logger . Error ( " " , zap . String ( " " , r . Name ) , zap . String ( " " , err . Error ( ) ) ) return nil , err } if err := tx . Commit ( ) . Error ; err != nil { tx . Rollback ( ) s . logger . Error ( " " , zap . String ( " " , r . Name ) , zap . String ( " " , err . Error ( ) ) ) return nil , err } return & api . RunnerDeleteResponse { } , nil }
Delete the specified runner from the db
Delete the specified runner from the db
/*
		Dont delete the cases
		if r.DeleteAllCases {
			// Delete all cases associated with the runner
		} else if r.DeleteCase {
			// Delete the single-case for the runner
		}
	*/ // start transaction for the delete // check if the runner is active // unless the delete is forced // set the runners server to inactive