@@ -324,62 +324,49 @@ async def run(self) -> None:
324324 return
325325 if debug :
326326 print (f"[installer] Started running" )
327- async with httpx .AsyncClient (
328- timeout = httpx .Timeout (70.0 ), verify = False
329- ) as client :
330- self .client = client
331- while not self .cancel_ :
332- if STATE .reconnect_with_credentials is not None :
333- if debug :
334- print ("[installer] Reconnection requested, stopping..." )
335- break
327+
328+ while not self .cancel_ :
329+ if STATE .reconnect_with_credentials is not None :
330+ if debug :
331+ print ("[installer] Reconnection requested, stopping..." )
332+ break
336333
337- self .running = True
338- try :
339- if debug :
340- print ("[installer] Active" )
341- api_key = ConfigModule .get_config_value ("Authentication" , "api-key" )
342- url = RequestFormatter .form_uri (
343- f"d/nodes/install/node/listen?node_id={ read_node_id ()} "
344- )
334+ self .running = True
335+ try :
336+ if debug :
337+ print ("[installer] Active" )
338+ host = RequestFormatter .form_uri (
339+ f"d/nodes/install/node/listen?node_id={ read_node_id ()} "
340+ )
345341
346- resp = await client .get (url , headers = {"X-API-KEY" : api_key })
347- if resp .status_code == httpx .codes .NO_CONTENT :
348- continue
342+ resp = resp = RequestFormatter .request ("get" , host , timeout = 70 )
349343
350- if not resp .is_success :
351- if debug :
352- print (
353- "[installer] facing difficulty communicating with the server , status code:" ,
354- resp .status_code ,
355- " | reconnecting " ,
356- )
357- print (Fore .YELLOW + str (resp .content ))
344+ if not resp .ok :
345+ if debug :
346+ print (
347+ "[installer] Request Error , status code:" ,
348+ resp .status_code ,
349+ "| retrying after 15 sec " ,
350+ )
351+ print (Fore .YELLOW + str (resp .content ))
358352
359- await asyncio .sleep (random . randint ( 1 , 3 ) )
360- continue
353+ await asyncio .sleep (15 )
354+ continue
361355
362- try :
363- data = resp .json ()
364- if data :
365- validated_data = Response (** data )
366- await self .on_message (validated_data )
367- except Exception as e :
368- print (f"[installer] Error parsing response: { e } " )
369- continue
356+ try :
357+ data = resp .json ()
358+ if data :
359+ validated_data = Response (** data )
360+ await self .on_message (validated_data )
361+ except Exception as e :
362+ print (f"[installer] Type Error in parsing response: { e } " )
363+ continue
370364
371- except httpx .ReadTimeout :
372- pass
373- except httpx .ConnectError :
374- if debug :
375- print ("[installer] Connection error, retrying..." )
376- await asyncio .sleep (random .randint (3 , 5 ))
377- except Exception :
378- if debug :
379- traceback .print_exc ()
380- if debug :
381- print ("[installer] RETRYING..." )
382- await asyncio .sleep (random .randint (1 , 3 ))
365+ except Exception :
366+ if debug :
367+ traceback .print_exc ()
368+ print ("[installer] RETRYING..." )
369+ await asyncio .sleep (random .randint (1 , 3 ))
383370
384371 self .running = False
385372 print ("[installer] Stopped running" )
0 commit comments