@@ -160,6 +160,7 @@ def run_report(
160160 scheduler_job_id = None ,
161161 run_synchronously = False ,
162162 mailfrom = None ,
163+ n_retries = 3 ,
163164) -> str :
164165 """
165166 Actually run the report in earnest.
@@ -173,6 +174,7 @@ def run_report(
173174 :param scheduler_job_id: `Optional[str]` if the job was triggered from the scheduler, this is the scheduler's job id
174175 :param run_synchronously: `bool` If True, then we will join the stderr monitoring thread until the job has completed
175176 :param mailfrom: `str` if passed, then this string will be used in the from field
177+ :param n_retries: The number of retries to attempt.
176178 :return: The unique job_id.
177179 """
178180 job_id = str (uuid .uuid4 ())
@@ -222,17 +224,13 @@ def run_report(
222224 json .dumps (overrides ),
223225 "--pdf-output" if generate_pdf_output else "--no-pdf-output" ,
224226 "--hide-code" if hide_code else "--show-code" ,
227+ "--n-retries" , str (n_retries ),
225228 ]
226229 + (["--prepare-notebook-only" ] if prepare_only else [])
227230 + ([f"--scheduler-job-id={ scheduler_job_id } " ] if scheduler_job_id is not None else [])
228231 + ([f"--mailfrom={ mailfrom } " ] if mailfrom is not None else [])
229232 )
230233 p = subprocess .Popen (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
231- time .sleep (5 )
232- p .poll ()
233- if p .returncode :
234- error_msg = "" .join ([chr (n ) for n in p .stderr .read ()])
235- raise RuntimeError (f"The process failed with the message: { error_msg } " )
236234
237235 stderr_thread = threading .Thread (
238236 target = _monitor_stderr ,
@@ -241,7 +239,12 @@ def run_report(
241239 stderr_thread .daemon = True
242240 stderr_thread .start ()
243241 if run_synchronously :
244- stderr_thread .join (120 ) # 2 minutes should be enough
242+ p .wait ()
243+ else :
244+ time .sleep (1 )
245+ p .poll ()
246+ if p .returncode :
247+ raise RuntimeError (f"The report execution failed with exit code { p .returncode } " )
245248
246249 return job_id
247250
0 commit comments