Exemple #1
0
def find_activity(history, scheduled_id=None, activity_id=None, input=None):
    """
    Finds an activity in a given workflow execution and returns a callable,
    some args and some kwargs so we can re-execute it.

    :type history: simpleflow.history.History
    :type scheduled_id: str
    :type activity_id: str
    :type input: Optional[dict[str, Any]]
    """
    found_activity = None
    for _, params in iteritems(history.activities):
        if params["scheduled_id"] == scheduled_id:
            found_activity = params
        if params["id"] == activity_id:
            found_activity = params

    if not found_activity:
        raise ValueError("Couldn't find activity.")

    # get the activity
    activity_str = found_activity["name"]
    dispatcher = dynamic_dispatcher.Dispatcher()
    activity = dispatcher.dispatch_activity(activity_str)

    # get the input
    input_ = input or found_activity["input"]
    if input_ is None:
        input_ = {}
    args = input_.get('args', ())
    kwargs = input_.get('kwargs', {})
    meta = input_.get('meta', {})

    # return everything
    return activity, args, kwargs, meta, found_activity
Exemple #2
0
def find_activity(history, scheduled_id=None, activity_id=None, input=None):
    """
    Finds an activity in a given workflow execution and returns a callable,
    some args and some kwargs so we can re-execute it.

    :type history: simpleflow.history.History
    :type scheduled_id: str
    :type activity_id: str
    :type input: Optional[dict[str, Any]]
    """
    found_activity = None
    for params in itervalues(history.activities):
        if params["scheduled_id"] == scheduled_id:
            found_activity = params
        if params["id"] == activity_id:
            found_activity = params

    if not found_activity:
        raise ValueError("Couldn't find activity.")

    # get the activity
    activity_str = found_activity["name"]
    dispatcher = dynamic_dispatcher.Dispatcher()
    activity = dispatcher.dispatch_activity(activity_str)

    # get the input
    input_ = input or found_activity["input"]
    if input_ is None:
        input_ = {}
    args = input_.get("args", ())
    kwargs = input_.get("kwargs", {})
    meta = input_.get("meta", {})

    kwargs["context"] = {
        "name": activity_str,
        "version": None,  # not stored in the activity dict
        "activity_id": found_activity["id"],
        "input": copy.deepcopy(input_),
    }

    # return everything
    return activity, args, kwargs, meta, found_activity
Exemple #3
0
 def __init__(self, dispatcher=None):
     self._dispatcher = dispatcher or dynamic_dispatcher.Dispatcher()