3636 MarkerTask ,
3737 TimerTask ,
3838 CancelTimerTask ,
39+ LambdaFunctionTask ,
3940)
4041from simpleflow .utils import (
4142 hex_hash ,
@@ -342,7 +343,7 @@ def _get_future_from_child_workflow_event(self, event):
342343 future .set_finished (json_loads_or_raw (event ['result' ]))
343344 elif state == 'failed' :
344345 future .set_exception (exceptions .TaskFailed (
345- name = event ['id ' ],
346+ name = event ['name ' ],
346347 reason = event ['reason' ],
347348 details = event .get ('details' ),
348349 ))
@@ -360,6 +361,43 @@ def _get_future_from_child_workflow_event(self, event):
360361
361362 return future
362363
364+ def _get_future_from_lambda_function_event (self , event ):
365+ """
366+
367+ :param event: child workflow event
368+ :type event: dict[str, Any]
369+ :return:
370+ :rtype: futures.Future
371+ """
372+ future = futures .Future ()
373+ state = event ['state' ]
374+
375+ if state == 'scheduled' :
376+ pass
377+ elif state == 'schedule_failed' :
378+ logger .info ('failed to schedule {}: {}' .format (
379+ event ['name' ],
380+ event ['cause' ],
381+ ))
382+ return None
383+ elif state == 'started' :
384+ future .set_running ()
385+ elif state == 'completed' :
386+ future .set_finished (json_loads_or_raw (event ['result' ]))
387+ elif state == 'failed' :
388+ future .set_exception (exceptions .TaskFailed (
389+ name = event ['name' ],
390+ reason = event ['reason' ],
391+ details = event .get ('details' ),
392+ ))
393+ elif state == 'timed_out' :
394+ future .set_exception (exceptions .TimeoutError (
395+ event ['timeout_type' ],
396+ None ,
397+ ))
398+
399+ return future
400+
363401 def _get_future_from_marker_event (self , a_task , event ):
364402 """Maps a marker event to a Future with the corresponding
365403 state.
@@ -497,6 +535,19 @@ def find_child_workflow_event(self, a_task, history):
497535 """
498536 return history .child_workflows .get (a_task .id )
499537
538+ def find_lambda_function_event (self , a_task , history ):
539+ """
540+ Get the event corresponding to a lambda function, if any.
541+
542+ :param a_task:
543+ :type a_task: LambdaFunctionTask
544+ :param history:
545+ :type history: simpleflow.history.History
546+ :return:
547+ :rtype: Optional[dict]
548+ """
549+ return history .lambda_functions .get (a_task .id )
550+
500551 def find_signal_event (self , a_task , history ):
501552 """
502553 Get the event corresponding to a signal, if any.
@@ -570,6 +621,7 @@ def find_timer_event(self, a_task, history):
570621 MarkerTask : find_marker_event ,
571622 TimerTask : find_timer_event ,
572623 CancelTimerTask : find_timer_event ,
624+ LambdaFunctionTask : find_lambda_function_event ,
573625 }
574626
575627 def find_event (self , a_task , history ):
@@ -644,12 +696,30 @@ def resume_child_workflow(self, a_task, event):
644696
645697 return future
646698
699+ def resume_lambda_function (self , a_task , event ):
700+ """
701+ Resume a child workflow.
702+
703+ :param a_task:
704+ :type a_task: LambdaTask
705+ :param event:
706+ :type event: dict
707+ :return:
708+ :rtype: simpleflow.futures.Future
709+ """
710+ future = self ._get_future_from_lambda_function_event (event )
711+
712+ if future .finished and future .exception :
713+ raise future .exception
714+
715+ return future
716+
647717 def schedule_task (self , a_task , task_list = None ):
648718 """
649719 Let a task schedule itself.
650720 If too many decisions are in flight, add a timer decision and raise ExecutionBlocked.
651721 :param a_task:
652- :type a_task: ActivityTask | WorkflowTask | SignalTask | MarkerTask
722+ :type a_task: SwfTask
653723 :param task_list:
654724 :type task_list: Optional[str]
655725 :raise: exceptions.ExecutionBlocked if too many decisions waiting
@@ -710,6 +780,7 @@ def _add_start_timer_decision(self, id):
710780 'external_workflow' : get_future_from_external_workflow_event ,
711781 'marker' : _get_future_from_marker_event ,
712782 'timer' : _get_future_from_timer_event ,
783+ 'lambda_function' : resume_lambda_function ,
713784 }
714785
715786 def resume (self , a_task , * args , ** kwargs ):
0 commit comments