@@ -235,20 +235,43 @@ def logs(
235235 return VisualList ("logs" , data = entries )
236236
237237 def run_synchronous (
238- self , outputfile : Union [str , Path , None ] = None ,
239- print = print , max_poll_interval = 60 , connection_retry_interval = 30
238+ self ,
239+ outputfile : Union [str , Path , None ] = None ,
240+ print = print ,
241+ max_poll_interval = 60 ,
242+ connection_retry_interval = 30 ,
243+ show_error_logs : bool = True ,
240244 ) -> BatchJob :
241- """Start the job, wait for it to finish and download result"""
245+ """
246+ Start the job, wait for it to finish and download result
247+
248+ :param outputfile: The path of a file to which a result can be written
249+ :param print: print/logging function to show progress/status
250+ :param max_poll_interval: maximum number of seconds to sleep between status polls
251+ :param connection_retry_interval: how long to wait when status poll failed due to connection issue
252+ :param show_error_logs: whether to automatically print error logs when the batch job failed.
253+
254+ .. versionchanged:: 0.37.0
255+ Added argument ``show_error_logs``.
256+ """
242257 self .start_and_wait (
243- print = print , max_poll_interval = max_poll_interval , connection_retry_interval = connection_retry_interval
258+ print = print ,
259+ max_poll_interval = max_poll_interval ,
260+ connection_retry_interval = connection_retry_interval ,
261+ show_error_logs = show_error_logs ,
244262 )
245263 # TODO #135 support multi file result sets too?
246264 if outputfile is not None :
247265 self .download_result (outputfile )
248266 return self
249267
250268 def start_and_wait (
251- self , print = print , max_poll_interval : int = 60 , connection_retry_interval : int = 30 , soft_error_max = 10
269+ self ,
270+ print = print ,
271+ max_poll_interval : int = 60 ,
272+ connection_retry_interval : int = 30 ,
273+ soft_error_max = 10 ,
274+ show_error_logs : bool = True ,
252275 ) -> BatchJob :
253276 """
254277 Start the batch job, poll its status and wait till it finishes (or fails)
@@ -257,7 +280,10 @@ def start_and_wait(
257280 :param max_poll_interval: maximum number of seconds to sleep between status polls
258281 :param connection_retry_interval: how long to wait when status poll failed due to connection issue
259282 :param soft_error_max: maximum number of soft errors (e.g. temporary connection glitches) to allow
260- :return:
283+ :param show_error_logs: whether to automatically print error logs when the batch job failed.
284+
285+ .. versionchanged:: 0.37.0
286+ Added argument ``show_error_logs``.
261287 """
262288 # TODO rename `connection_retry_interval` to something more generic?
263289 start_time = time .time ()
@@ -314,13 +340,13 @@ def soft_error(message: str):
314340 poll_interval = min (1.25 * poll_interval , max_poll_interval )
315341
316342 if status != "finished" :
317- # TODO: allow to disable this printing logs (e.g. in non-interactive contexts)?
318343 # TODO: render logs jupyter-aware in a notebook context?
319- print (f"Your batch job { self .job_id !r} failed. Error logs:" )
320- print (self .logs (level = logging .ERROR ))
321- print (
322- f"Full logs can be inspected in an openEO (web) editor or with `connection.job({ self .job_id !r} ).logs()`."
323- )
344+ if show_error_logs :
345+ print (f"Your batch job { self .job_id !r} failed. Error logs:" )
346+ print (self .logs (level = logging .ERROR ))
347+ print (
348+ f"Full logs can be inspected in an openEO (web) editor or with `connection.job({ self .job_id !r} ).logs()`."
349+ )
324350 raise JobFailedException (
325351 f"Batch job { self .job_id !r} didn't finish successfully. Status: { status } (after { elapsed ()} )." ,
326352 job = self ,
0 commit comments