@@ -29,7 +29,7 @@ public static function getLatestBitbucketTag(string $name, array $source): array
2929 logger ()->debug ("finding {$ name } source from bitbucket tag " );
3030 $ data = json_decode (self ::curlExec (
3131 url: "https://api.bitbucket.org/2.0/repositories/ {$ source ['repo ' ]}/refs/tags " ,
32- retry : self ::getRetryTime ()
32+ retries : self ::getRetryAttempts ()
3333 ), true );
3434 $ ver = $ data ['values ' ][0 ]['name ' ];
3535 if (!$ ver ) {
@@ -39,7 +39,7 @@ public static function getLatestBitbucketTag(string $name, array $source): array
3939 $ headers = self ::curlExec (
4040 url: $ url ,
4141 method: 'HEAD ' ,
42- retry : self ::getRetryTime ()
42+ retries : self ::getRetryAttempts ()
4343 );
4444 preg_match ('/^content-disposition:\s+attachment;\s*filename=("?)(?<filename>.+\.tar\.gz)\1/im ' , $ headers , $ matches );
4545 if ($ matches ) {
@@ -67,7 +67,7 @@ public static function getLatestGithubTarball(string $name, array $source, strin
6767 $ data = json_decode (self ::curlExec (
6868 url: "https://api.github.com/repos/ {$ source ['repo ' ]}/ {$ type }" ,
6969 hooks: [[CurlHook::class, 'setupGithubToken ' ]],
70- retry : self ::getRetryTime ()
70+ retries : self ::getRetryAttempts ()
7171 ), true );
7272
7373 $ url = null ;
@@ -91,7 +91,7 @@ public static function getLatestGithubTarball(string $name, array $source, strin
9191 url: $ url ,
9292 method: 'HEAD ' ,
9393 hooks: [[CurlHook::class, 'setupGithubToken ' ]],
94- retry : self ::getRetryTime ()
94+ retries : self ::getRetryAttempts ()
9595 );
9696 preg_match ('/^content-disposition:\s+attachment;\s*filename=("?)(?<filename>.+\.tar\.gz)\1/im ' , $ headers , $ matches );
9797 if ($ matches ) {
@@ -118,7 +118,7 @@ public static function getLatestGithubRelease(string $name, array $source, bool
118118 $ data = json_decode (self ::curlExec (
119119 url: "https://api.github.com/repos/ {$ source ['repo ' ]}/releases " ,
120120 hooks: [[CurlHook::class, 'setupGithubToken ' ]],
121- retry : self ::getRetryTime ()
121+ retries : self ::getRetryAttempts ()
122122 ), true );
123123 $ url = null ;
124124 foreach ($ data as $ release ) {
@@ -156,7 +156,7 @@ public static function getLatestGithubRelease(string $name, array $source, bool
156156 public static function getFromFileList (string $ name , array $ source ): array
157157 {
158158 logger ()->debug ("finding {$ name } source from file list " );
159- $ page = self ::curlExec ($ source ['url ' ], retry : self ::getRetryTime ());
159+ $ page = self ::curlExec ($ source ['url ' ], retries : self ::getRetryAttempts ());
160160 preg_match_all ($ source ['regex ' ], $ page , $ matches );
161161 if (!$ matches ) {
162162 throw new DownloaderException ("Failed to get {$ name } version " );
@@ -201,7 +201,7 @@ public static function downloadFile(string $name, string $url, string $filename,
201201 }
202202 };
203203 self ::registerCancelEvent ($ cancel_func );
204- self ::curlDown (url: $ url , path: FileSystem::convertPath (DOWNLOAD_PATH . "/ {$ filename }" ), retry: self ::getRetryTime ());
204+ self ::curlDown (url: $ url , path: FileSystem::convertPath (DOWNLOAD_PATH . "/ {$ filename }" ), retry: self ::getRetryAttempts ());
205205 self ::unregisterCancelEvent ();
206206 logger ()->debug ("Locking {$ filename }" );
207207 if ($ download_as === SPC_DOWNLOAD_PRE_BUILT ) {
@@ -366,7 +366,7 @@ public static function downloadPackage(string $name, ?array $pkg = null, bool $f
366366 $ pkg ['url ' ],
367367 $ pkg ['rev ' ],
368368 $ pkg ['extract ' ] ?? null ,
369- self ::getRetryTime (),
369+ self ::getRetryAttempts (),
370370 SPC_DOWNLOAD_PRE_BUILT
371371 );
372372 break ;
@@ -472,7 +472,7 @@ public static function downloadSource(string $name, ?array $source = null, bool
472472 $ source ['url ' ],
473473 $ source ['rev ' ],
474474 $ source ['path ' ] ?? null ,
475- self ::getRetryTime (),
475+ self ::getRetryAttempts (),
476476 $ download_as
477477 );
478478 break ;
@@ -504,7 +504,7 @@ public static function downloadSource(string $name, ?array $source = null, bool
504504 *
505505 * @throws DownloaderException
506506 */
507- public static function curlExec (string $ url , string $ method = 'GET ' , array $ headers = [], array $ hooks = [], int $ retry = 0 ): string
507+ public static function curlExec (string $ url , string $ method = 'GET ' , array $ headers = [], array $ hooks = [], int $ retries = 0 ): string
508508 {
509509 foreach ($ hooks as $ hook ) {
510510 $ hook ($ method , $ url , $ headers );
@@ -551,9 +551,10 @@ public static function curlExec(string $url, string $method = 'GET', array $head
551551 }
552552 return implode ("\n" , $ output );
553553 } catch (DownloaderException $ e ) {
554- if ($ retry > 0 ) {
555- logger ()->notice ('Retrying curl exec ... ' );
556- return self ::curlExec ($ url , $ method , $ headers , $ hooks , $ retry - 1 );
554+ if ($ retries > 0 ) {
555+ logger ()->notice ('Retrying curl exec after 5 seconds... ' );
556+ sleep (5 );
557+ return self ::curlExec ($ url , $ method , $ headers , $ hooks , $ retries - 1 );
557558 }
558559 throw $ e ;
559560 }
@@ -628,9 +629,9 @@ private static function unregisterCancelEvent(): void
628629 }
629630 }
630631
631- private static function getRetryTime (): int
632+ private static function getRetryAttempts (): int
632633 {
633- return intval (getenv ('SPC_RETRY_TIME ' ) ? getenv ( ' SPC_RETRY_TIME ' ) : 0 );
634+ return intval (getenv ('SPC_DOWNLOAD_RETRIES ' ) ?: 0 );
634635 }
635636
636637 /**
0 commit comments