@@ -236,19 +236,30 @@ def logs(
236236
237237 def run_synchronous (
238238 self , outputfile : Union [str , Path , None ] = None ,
239- print = print , max_poll_interval = 60 , connection_retry_interval = 30
239+ print = print , max_poll_interval = 60 , connection_retry_interval = 30 , log_error = True
240240 ) -> BatchJob :
241- """Start the job, wait for it to finish and download result"""
241+ """
242+ Start the job, wait for it to finish and download result
243+
244+ :param outputfile: The path of a file to which a result can be written
245+ :param print: print/logging function to show progress/status
246+ :param max_poll_interval: maximum number of seconds to sleep between status polls
247+ :param connection_retry_interval: how long to wait when status poll failed due to connection issue
248+ :param log_error: whether to print error logs
249+ :return:
250+ """
242251 self .start_and_wait (
243- print = print , max_poll_interval = max_poll_interval , connection_retry_interval = connection_retry_interval
252+ print = print , max_poll_interval = max_poll_interval , connection_retry_interval = connection_retry_interval ,
253+ log_error = log_error
244254 )
245255 # TODO #135 support multi file result sets too?
246256 if outputfile is not None :
247257 self .download_result (outputfile )
248258 return self
249259
250260 def start_and_wait (
251- self , print = print , max_poll_interval : int = 60 , connection_retry_interval : int = 30 , soft_error_max = 10
261+ self , print = print , max_poll_interval : int = 60 , connection_retry_interval : int = 30 , soft_error_max = 10 ,
262+ log_error = True
252263 ) -> BatchJob :
253264 """
254265 Start the batch job, poll its status and wait till it finishes (or fails)
@@ -257,6 +268,7 @@ def start_and_wait(
257268 :param max_poll_interval: maximum number of seconds to sleep between status polls
258269 :param connection_retry_interval: how long to wait when status poll failed due to connection issue
259270 :param soft_error_max: maximum number of soft errors (e.g. temporary connection glitches) to allow
271+ :param log_error: whether to print error logs
260272 :return:
261273 """
262274 # TODO rename `connection_retry_interval` to something more generic?
@@ -314,13 +326,13 @@ def soft_error(message: str):
314326 poll_interval = min (1.25 * poll_interval , max_poll_interval )
315327
316328 if status != "finished" :
317- # TODO: allow to disable this printing logs (e.g. in non-interactive contexts)?
318329 # 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- )
330+ if log_error :
331+ print (f"Your batch job { self .job_id !r} failed. Error logs:" )
332+ print (self .logs (level = logging .ERROR ))
333+ print (
334+ f"Full logs can be inspected in an openEO (web) editor or with `connection.job({ self .job_id !r} ).logs()`."
335+ )
324336 raise JobFailedException (
325337 f"Batch job { self .job_id !r} didn't finish successfully. Status: { status } (after { elapsed ()} )." ,
326338 job = self ,
0 commit comments