@@ -343,9 +343,10 @@ def __init__(self, error_msg):
343
343
self .error_msg = error_msg
344
344
super ().__init__ ()
345
345
346
- def call_install_packs_request (packs ):
346
+ def call_install_packs_request (packs , attempts_count = 1 ):
347
347
try :
348
- logging .debug (f'Installing the following packs on server { host } :\n { [pack ["id" ] for pack in packs ]} ' )
348
+ logging .info (f'Installing packs { ", " .join ([p .get ("id" ) for p in packs_to_install ])} on server { host } . '
349
+ f'Attempts left on failure: { attempts_count } .' )
349
350
response_data , status_code , _ = demisto_client .generic_request_func (client ,
350
351
path = '/contentpacks/marketplace/install' ,
351
352
method = 'POST' ,
@@ -362,20 +363,25 @@ def call_install_packs_request(packs):
362
363
363
364
except ApiException as ex :
364
365
try :
365
- if 'timeout awaiting response' in ex .body :
366
+ if ex .status in [502 , 599 ]:
367
+ if attempts_count <= 1 :
368
+ raise ex
369
+ else :
370
+ call_install_packs_request (packs , attempts_count - 1 )
371
+ elif 'timeout awaiting response' in ex .body :
366
372
raise GCPTimeOutException (ex .body )
367
- if malformed_ids := find_malformed_pack_id (ex .body ):
373
+ elif malformed_ids := find_malformed_pack_id (ex .body ):
368
374
raise MalformedPackException (malformed_ids )
369
- if 'Item not found' in ex .body :
375
+ elif 'Item not found' in ex .body :
370
376
raise GeneralItemNotFoundError (ex .body )
371
- raise ex
377
+ else :
378
+ raise ex
372
379
except Exception :
373
- logging .debug (f'The error occurred during parsing the install error: { str (ex )} ' )
380
+ logging .debug (f'An error occurred during parsing the install error: { str (ex )} ' )
374
381
raise ex
375
382
try :
376
- logging .info (f'Installing packs { ", " .join ([p .get ("id" ) for p in packs_to_install ])} on server { host } ' )
377
383
try :
378
- call_install_packs_request (packs_to_install )
384
+ call_install_packs_request (packs_to_install , attempts_count = 3 )
379
385
380
386
except MalformedPackException as e :
381
387
# if this is malformed pack error, remove malformed packs and retry until success
@@ -457,7 +463,8 @@ def search_pack_and_its_dependencies(client: demisto_client,
457
463
458
464
lock .acquire ()
459
465
if one_pack_and_its_dependencies_in_batch :
460
- batch_packs_install_request_body .append (current_packs_to_install ) # type:ignore[union-attr]
466
+ pack_and_its_dependencies = {p ['id' ]: p for p in current_packs_to_install }
467
+ batch_packs_install_request_body .append (list (pack_and_its_dependencies .values ())) # type:ignore[union-attr]
461
468
else :
462
469
for pack in current_packs_to_install :
463
470
if pack ['id' ] not in packs_to_install :
0 commit comments