@@ -303,15 +303,40 @@ public function addArtifactsRepoToComposer(): bool
303
303
*/
304
304
public function addDependencyToComposer (string $ name , string $ version ): bool
305
305
{
306
- return $ this ->taskComposerRequire ('composer ' )
307
- ->dependency ($ name , $ version )
308
- ->noInteraction ()
309
- ->option ('--no-update ' )
310
- ->printOutput ($ this ->_getConfig ('printOutput ' ))
311
- ->interactive (false )
312
- ->dir ($ this ->getWorkDirPath ())
313
- ->run ()
314
- ->wasSuccessful ();
306
+ return $ this ->retry (
307
+ function () use ($ name , $ version ) {
308
+ return $ this ->taskComposerRequire ('composer ' )
309
+ ->dependency ($ name , $ version )
310
+ ->noInteraction ()
311
+ ->option ('--no-update ' )
312
+ ->printOutput ($ this ->_getConfig ('printOutput ' ))
313
+ ->interactive (false )
314
+ ->dir ($ this ->getWorkDirPath ())
315
+ ->run ()
316
+ ->wasSuccessful ();
317
+ }
318
+ );
319
+ }
320
+
321
+ /**
322
+ * @param callable $callback
323
+ * @param int $retries
324
+ * @return bool
325
+ */
326
+ private function retry (callable $ callback , int $ retries = 2 ): bool
327
+ {
328
+ $ result = false ;
329
+
330
+ for ($ i = $ retries ; $ i > 0 ; $ i --) {
331
+ $ result = $ callback ();
332
+ if ($ result ) {
333
+ return $ result ;
334
+ }
335
+
336
+ sleep (5 );
337
+ }
338
+
339
+ return $ result ;
315
340
}
316
341
317
342
/**
@@ -507,12 +532,16 @@ public function replaceImagesWithCurrentDockerVersion(): bool
507
532
*/
508
533
public function composerUpdate (): bool
509
534
{
510
- return $ this ->taskComposerUpdate ('composer ' )
511
- ->printOutput ($ this ->_getConfig ('printOutput ' ))
512
- ->interactive (false )
513
- ->dir ($ this ->getWorkDirPath ())
514
- ->run ()
515
- ->wasSuccessful ();
535
+ return $ this ->retry (
536
+ function () {
537
+ return $ this ->taskComposerUpdate ('composer ' )
538
+ ->printOutput ($ this ->_getConfig ('printOutput ' ))
539
+ ->interactive (false )
540
+ ->dir ($ this ->getWorkDirPath ())
541
+ ->run ()
542
+ ->wasSuccessful ();
543
+ }
544
+ );
516
545
}
517
546
518
547
/**
0 commit comments