@@ -994,11 +994,15 @@ public function sftpConnectionInfo()
994994 }
995995
996996 /**
997- * "Wake" a site
997+ * "Wake" a site with retries
998998 *
999+ * @param int $maxRetries Maximum number of retries
1000+ * @param int $delay Delay between retries in seconds
9991001 * @return array
1002+ *
1003+ * @throws \Pantheon\Terminus\Exceptions\TerminusException
10001004 */
1001- public function wake (): array
1005+ public function wake (int $ maxRetries = 3 , int $ delay = 5 ): array
10021006 {
10031007 $ domains = array_filter (
10041008 $ this ->getDomains ()->all (),
@@ -1007,16 +1011,44 @@ function ($domain) {
10071011 return (!empty ($ domain_type ) && "platform " == $ domain_type );
10081012 }
10091013 );
1014+
1015+ if (empty ($ domains )) {
1016+ throw new TerminusException ('No valid domains found for health check. ' );
1017+ }
1018+
10101019 $ domain = array_pop ($ domains );
1011- $ response = $ this ->request ()->request (
1012- "https:// {$ domain ->id }/pantheon_healthcheck "
1013- );
1014- return [
1015- 'success ' => ($ response ['status_code ' ] === 200 ),
1016- 'styx ' => $ response ['headers ' ]['X-Pantheon-Styx-Hostname ' ],
1017- 'response ' => $ response ,
1018- 'target ' => $ domain ->id ,
1019- ];
1020+ $ attempt = 0 ;
1021+ $ success = false ;
1022+
1023+ while ($ attempt < $ maxRetries && !$ success ) {
1024+ $ attempt ++;
1025+ try {
1026+ $ response = $ this ->request ()->request (
1027+ "https:// {$ domain ->id }/pantheon_healthcheck "
1028+ );
1029+ $ success = ($ response ['status_code ' ] === 200 );
1030+ if ($ success ) {
1031+ return [
1032+ 'success ' => true ,
1033+ 'styx ' => $ response ['headers ' ]['X-Pantheon-Styx-Hostname ' ],
1034+ 'response ' => $ response ,
1035+ 'target ' => $ domain ->id ,
1036+ ];
1037+ }
1038+ } catch (\Exception $ e ) {
1039+ $ this ->logger ->debug (
1040+ "Failed to wake the site: \n{message} " ,
1041+ ['message ' => $ e ->getMessage (),]
1042+ );
1043+ $ success = false ;
1044+ }
1045+
1046+ if (!$ success ) {
1047+ sleep ($ delay ); // Delay before retrying
1048+ }
1049+ }
1050+
1051+ throw new TerminusException ('Failed to wake the site after ' . $ maxRetries . ' attempts. ' );
10201052 }
10211053
10221054 /**
0 commit comments