@@ -1468,26 +1468,31 @@ protected function importSubmission(Event $event, EventData $data): void
14681468 }
14691469
14701470 if ($ submissionDownloadSucceeded ) {
1471- try {
1472- $ response = $ this ->httpClient ->request ('GET ' , $ zipUrl );
1473- $ ziphandler = fopen ($ zipFile , 'w ' );
1474- if ($ response ->getStatusCode () !== 200 ) {
1475- // TODO: Retry a couple of times.
1471+ $ tries = 1 ;
1472+ do {
1473+ try {
1474+ $ response = $ this ->httpClient ->request ('GET ' , $ zipUrl );
1475+ $ ziphandler = fopen ($ zipFile , 'w ' );
1476+ if ($ response ->getStatusCode () !== 200 ) {
1477+ $ this ->addOrUpdateWarning ($ event , $ data ->id , ExternalSourceWarning::TYPE_SUBMISSION_ERROR , [
1478+ 'message ' => "Cannot download ZIP from $ zipUrl after trying $ tries times " ,
1479+ ]);
1480+ $ submissionDownloadSucceeded = false ;
1481+ // Sleep a bit before retrying
1482+ sleep (3 );
1483+ }
1484+ $ tries ++;
1485+ } catch (TransportExceptionInterface $ e ) {
14761486 $ this ->addOrUpdateWarning ($ event , $ data ->id , ExternalSourceWarning::TYPE_SUBMISSION_ERROR , [
1477- 'message ' => ' Cannot download ZIP from ' . $ zipUrl ,
1487+ 'message ' => " Cannot download ZIP from $ zipUrl after trying $ tries times: " . $ e -> getMessage () ,
14781488 ]);
1489+ if (isset ($ ziphandler )) {
1490+ fclose ($ ziphandler );
1491+ }
1492+ unlink ($ zipFile );
14791493 $ submissionDownloadSucceeded = false ;
14801494 }
1481- } catch (TransportExceptionInterface $ e ) {
1482- $ this ->addOrUpdateWarning ($ event , $ data ->id , ExternalSourceWarning::TYPE_SUBMISSION_ERROR , [
1483- 'message ' => 'Cannot download ZIP from ' . $ zipUrl . ': ' . $ e ->getMessage (),
1484- ]);
1485- if (isset ($ ziphandler )) {
1486- fclose ($ ziphandler );
1487- }
1488- unlink ($ zipFile );
1489- $ submissionDownloadSucceeded = false ;
1490- }
1495+ } while ($ tries <= 3 && !$ submissionDownloadSucceeded );
14911496 }
14921497
14931498 if (isset ($ response , $ ziphandler ) && $ submissionDownloadSucceeded ) {
0 commit comments