3535from connect .eaas .core .enums import (
3636 ResultType ,
3737)
38- from connect .eaas .core .logging import (
39- RequestLogger ,
40- )
4138from connect .eaas .core .proto import (
4239 Task ,
4340 TaskOutput ,
5451 TRANSFORMATION_TASK_MAX_PARALLEL_LINES ,
5552 UPLOAD_CHUNK_SIZE ,
5653)
54+ from connect .eaas .runner .logging import (
55+ RequestLogger ,
56+ )
5757from connect .eaas .runner .managers .base import (
5858 TasksManagerBase ,
5959)
@@ -163,7 +163,7 @@ async def build_response(self, task_data, future):
163163 except Exception as e :
164164 cause = (
165165 str (e ) if not isinstance (e , asyncio .TimeoutError )
166- else 'timed out after {timeout} s'
166+ else f 'timed out after { timeout } s'
167167 )
168168 self .log_exception (task_data , e )
169169 await self ._fail_task (task_data , cause )
@@ -251,7 +251,10 @@ async def process_transformation(self, task_data, tfn_request, method):
251251 await client .conversations [task_data .input .object_id ].messages .create (
252252 payload = {
253253 'type' : 'message' ,
254- 'text' : f'Transformation request processing failed: { str (e ) or "timed out" } ' ,
254+ 'text' : (
255+ 'Transformation request processing failed: '
256+ f'{ self .format_exception_message (e )} '
257+ ),
255258 },
256259 )
257260 return TransformationResponse .fail (output = str (e ))
@@ -381,7 +384,6 @@ async def process_rows(self, read_queue, result_store, method, tfn_request, logg
381384 async def transform_row (self , method , row_idx , row , row_styles ):
382385 try :
383386 if ROW_DELETED_MARKER in list (row .values ()):
384- # await result_store.put((row_idx, RowTransformationResponse.delete()))
385387 return RowTransformationResponse .delete ()
386388 kwargs = {}
387389 if 'row_styles' in inspect .signature (method ).parameters :
@@ -394,19 +396,24 @@ async def transform_row(self, method, row_idx, row, row_styles):
394396 self .executor ,
395397 functools .partial (method , row , ** kwargs ),
396398 )
399+ timeout = self .config .get_timeout ('row_transformation' )
397400 response = await asyncio .wait_for (
398401 awaitable ,
399- timeout = self . config . get_timeout ( 'row_transformation' ) ,
402+ timeout = timeout ,
400403 )
401404 if not isinstance (response , RowTransformationResponse ):
402405 raise RowTransformationError (f'invalid row tranformation response: { response } ' )
403406 if response .status == ResultType .FAIL :
404407 raise RowTransformationError (f'row transformation failed: { response .output } ' )
405408 return response
406409 except Exception as e :
410+ cause = (
411+ str (e ) if not isinstance (e , asyncio .TimeoutError )
412+ else f'timed out after { timeout } s'
413+ )
407414 raise RowTransformationError (
408415 f'Error applying transformation function { method .__name__ } '
409- f'to row #{ row_idx } : { str ( e ) } .' ,
416+ f'to row #{ row_idx } : { cause } .' ,
410417 ) from e
411418
412419 def write_excel (
@@ -525,3 +532,11 @@ async def chunks_iterator(): # pragma: no cover
525532 payload = {'files' : {'output' : {'id' : media_file_id }}},
526533 )
527534 await client (ns ).requests [task_data .input .object_id ]('process' ).post ()
535+
536+ def format_exception_message (self , e ):
537+ if isinstance (e , asyncio .CancelledError ):
538+ return 'cancelled'
539+ elif isinstance (e , asyncio .TimeoutError ):
540+ return 'timed out'
541+ else :
542+ return str (e ) or repr (e )
0 commit comments