@@ -58,23 +58,34 @@ public async Task<Machine> CreateNewRunner(string arch, string size, string runn
5858
5959 try
6060 {
61- // Select node
62- var resources = ( await client . Cluster . Resources . GetAsync ( "vm" ) ) . ToList ( ) ;
63- var availableNodes = resources . Select ( x => x . Node ) . Distinct ( ) . ToList ( ) ;
64-
65- var vmCountByNode = availableNodes
66- . GroupJoin (
67- resources . Where ( x => x . Name . StartsWith ( Program . Config . RunnerPrefix ) ) ,
68- node => node ,
69- resource => resource . Node ,
70- ( node , matchingResources ) => new { Node = node , Count = matchingResources . Count ( ) }
71- )
72- . ToList ( ) ;
73-
74-
75- var nodeWithLeastRunners = vmCountByNode . OrderBy ( x => x . Count ) . First ( ) ;
76- var selectedNode = nodeWithLeastRunners . Node ;
61+
62+ string selectedNode = _mainNode ;
7763
64+ // Select node
65+ try
66+ {
67+ var resources = ( await client . Cluster . Resources . GetAsync ( "vm" ) ) . ToList ( ) ;
68+ var availableNodes = resources . Select ( x => x . Node ) . Distinct ( ) . ToList ( ) ;
69+
70+ var vmCountByNode = availableNodes
71+ . GroupJoin (
72+ resources . Where ( x => x . Name . StartsWith ( Program . Config . RunnerPrefix ) ) ,
73+ node => node ,
74+ resource => resource . Node ,
75+ ( node , matchingResources ) => new { Node = node , Count = matchingResources . Count ( ) }
76+ )
77+ . ToList ( ) ;
78+
79+
80+ var nodeWithLeastRunners = vmCountByNode . OrderBy ( x => x . Count ) . First ( ) ;
81+ selectedNode = nodeWithLeastRunners . Node ;
82+ }
83+ catch ( Exception ex )
84+ {
85+ _logger . LogError ( ex , $ "Unable to get available nodes - using main node: { ex . GetFullExceptionDetails ( ) } ") ;
86+ Thread . Sleep ( 500 ) ;
87+ }
88+
7889 Result newVmIdResult = await client . Cluster . Nextid . Nextid ( ) ;
7990 newVmId = int . Parse ( newVmIdResult . Response . data ) ;
8091
0 commit comments