3636 MarkerTask ,
3737 TimerTask ,
3838 CancelTimerTask ,
39+ LambdaFunctionTask ,
3940)
4041from simpleflow .utils import (
4142 hex_hash ,
@@ -333,7 +334,7 @@ def _get_future_from_child_workflow_event(self, event):
333334 future .set_finished (json_loads_or_raw (event ['result' ]))
334335 elif state == 'failed' :
335336 future .set_exception (exceptions .TaskFailed (
336- name = event ['id ' ],
337+ name = event ['name ' ],
337338 reason = event ['reason' ],
338339 details = event .get ('details' ),
339340 ))
@@ -351,6 +352,43 @@ def _get_future_from_child_workflow_event(self, event):
351352
352353 return future
353354
355+ def _get_future_from_lambda_function_event (self , event ):
356+ """
357+
358+ :param event: child workflow event
359+ :type event: dict[str, Any]
360+ :return:
361+ :rtype: futures.Future
362+ """
363+ future = futures .Future ()
364+ state = event ['state' ]
365+
366+ if state == 'scheduled' :
367+ pass
368+ elif state == 'schedule_failed' :
369+ logger .info ('failed to schedule {}: {}' .format (
370+ event ['name' ],
371+ event ['cause' ],
372+ ))
373+ return None
374+ elif state == 'started' :
375+ future .set_running ()
376+ elif state == 'completed' :
377+ future .set_finished (json_loads_or_raw (event ['result' ]))
378+ elif state == 'failed' :
379+ future .set_exception (exceptions .TaskFailed (
380+ name = event ['name' ],
381+ reason = event ['reason' ],
382+ details = event .get ('details' ),
383+ ))
384+ elif state == 'timed_out' :
385+ future .set_exception (exceptions .TimeoutError (
386+ event ['timeout_type' ],
387+ None ,
388+ ))
389+
390+ return future
391+
354392 def _get_future_from_marker_event (self , a_task , event ):
355393 """Maps a marker event to a Future with the corresponding
356394 state.
@@ -488,6 +526,19 @@ def find_child_workflow_event(self, a_task, history):
488526 """
489527 return history .child_workflows .get (a_task .id )
490528
529+ def find_lambda_function_event (self , a_task , history ):
530+ """
531+ Get the event corresponding to a lambda function, if any.
532+
533+ :param a_task:
534+ :type a_task: LambdaFunctionTask
535+ :param history:
536+ :type history: simpleflow.history.History
537+ :return:
538+ :rtype: Optional[dict]
539+ """
540+ return history .lambda_functions .get (a_task .id )
541+
491542 def find_signal_event (self , a_task , history ):
492543 """
493544 Get the event corresponding to a signal, if any.
@@ -561,6 +612,7 @@ def find_timer_event(self, a_task, history):
561612 MarkerTask : find_marker_event ,
562613 TimerTask : find_timer_event ,
563614 CancelTimerTask : find_timer_event ,
615+ LambdaFunctionTask : find_lambda_function_event ,
564616 }
565617
566618 def find_event (self , a_task , history ):
@@ -635,12 +687,30 @@ def resume_child_workflow(self, a_task, event):
635687
636688 return future
637689
690+ def resume_lambda_function (self , a_task , event ):
691+ """
692+ Resume a child workflow.
693+
694+ :param a_task:
695+ :type a_task: LambdaTask
696+ :param event:
697+ :type event: dict
698+ :return:
699+ :rtype: simpleflow.futures.Future
700+ """
701+ future = self ._get_future_from_lambda_function_event (event )
702+
703+ if future .finished and future .exception :
704+ raise future .exception
705+
706+ return future
707+
638708 def schedule_task (self , a_task , task_list = None ):
639709 """
640710 Let a task schedule itself.
641711 If too many decisions are in flight, add a timer decision and raise ExecutionBlocked.
642712 :param a_task:
643- :type a_task: ActivityTask | WorkflowTask | SignalTask | MarkerTask
713+ :type a_task: SwfTask
644714 :param task_list:
645715 :type task_list: Optional[str]
646716 :raise: exceptions.ExecutionBlocked if too many decisions waiting
@@ -701,6 +771,7 @@ def _add_start_timer_decision(self, id):
701771 'external_workflow' : get_future_from_external_workflow_event ,
702772 'marker' : _get_future_from_marker_event ,
703773 'timer' : _get_future_from_timer_event ,
774+ 'lambda_function' : resume_lambda_function ,
704775 }
705776
706777 def resume (self , a_task , * args , ** kwargs ):
0 commit comments