22
22
import os
23
23
import re
24
24
import sys
25
+ import time
25
26
import subprocess
26
27
27
28
from sparktestsupport import SPARK_HOME , USER_HOME , ERROR_CODES
@@ -146,7 +147,7 @@ def exec_maven(mvn_args=()):
146
147
run_cmd (flags + mvn_args )
147
148
148
149
149
- def exec_sbt (sbt_args = ()):
150
+ def exec_sbt (sbt_args = (), retry = 1 ):
150
151
"""Will call SBT in the current directory with the list of mvn_args passed
151
152
in and returns the subprocess for any further processing"""
152
153
@@ -156,17 +157,39 @@ def exec_sbt(sbt_args=()):
156
157
b"^.*[info].*Resolving" + b"|" + b"^.*[warn].*Merging" + b"|" + b"^.*[info].*Including"
157
158
)
158
159
159
- # NOTE: echo "q" is needed because sbt on encountering a build file
160
- # with failure (either resolution or compilation) prompts the user for
161
- # input either q, r, etc to quit or retry. This echo is there to make it
162
- # not block.
163
- echo_proc = subprocess .Popen (["echo" , '"q\n "' ], stdout = subprocess .PIPE )
164
- sbt_proc = subprocess .Popen (sbt_cmd , stdin = echo_proc .stdout , stdout = subprocess .PIPE )
165
- echo_proc .wait ()
166
- for line in iter (sbt_proc .stdout .readline , b"" ):
167
- if not sbt_output_filter .match (line ):
168
- print (line .decode ("utf-8" ), end = "" )
169
- retcode = sbt_proc .wait ()
160
+ attempts = 0
161
+ while attempts < retry :
162
+ attempts += 1
163
+
164
+ # NOTE: echo "q" is needed because sbt on encountering a build file
165
+ # with failure (either resolution or compilation) prompts the user for
166
+ # input either q, r, etc to quit or retry. This echo is there to make it
167
+ # not block.
168
+ echo_proc = subprocess .Popen (["echo" , '"q\n "' ], stdout = subprocess .PIPE )
169
+ sbt_proc = subprocess .Popen (sbt_cmd , stdin = echo_proc .stdout , stdout = subprocess .PIPE )
170
+ echo_proc .wait ()
171
+ for line in iter (sbt_proc .stdout .readline , b"" ):
172
+ if not sbt_output_filter .match (line ):
173
+ print (line .decode ("utf-8" ), end = "" )
174
+ retcode = sbt_proc .wait ()
175
+
176
+ if retcode == 0 :
177
+ # successfully executed the command
178
+ return
179
+ elif attempts < retry :
180
+ # Will retry the command.
181
+ if retcode < 0 :
182
+ print (
183
+ "[error] running" ,
184
+ " " .join (sbt_cmd ),
185
+ "; process was terminated by signal" ,
186
+ - retcode ,
187
+ )
188
+ else :
189
+ print ("[error] running" , " " .join (sbt_cmd ), "; received return code" , retcode )
190
+
191
+ time .sleep (10 )
192
+ print ("[info] Retrying command" , sbt_cmd , "; attempt " , attempts + 1 , " of " , retry )
170
193
171
194
if retcode != 0 :
172
195
exit_from_command_with_retcode (sbt_cmd , retcode )
@@ -255,7 +278,7 @@ def build_spark_sbt(extra_profiles):
255
278
256
279
print ("[info] Building Spark using SBT with these arguments: " , " " .join (profiles_and_goals ))
257
280
258
- exec_sbt (profiles_and_goals )
281
+ exec_sbt (profiles_and_goals , retry = 3 )
259
282
260
283
261
284
def build_spark_unidoc_sbt (extra_profiles ):
0 commit comments