microsoft / durabletask-python

A Durable Task Python SDK compatible with Dapr Workflow and its underlying Durable Task engine
MIT License
13 stars 6 forks source link

Question: conditionally skip multiple actions based on an event #29

Open max-arnold opened 3 months ago

max-arnold commented 3 months ago

Let's assume the following orchestration:

def orch(ctx: task.OrchestrationContext, _):
    result = yield ctx.call_activity(hello, input='Tokyo')
    if result:
         yield ctx.call_activity(hello, input='Seattle')
    else:
         yield ctx.call_activity(hello, input='London')

    yield ctx.call_activity(hello, input='END')
    return None

How can I modify it to listen for an external event that will skip the pending activities and jump directly to the END one?

In other words, how to model complex FSMs when some of the state transitions (fast-forward, or continue-as-new) are triggered externally and I do not want to wrap every activity call with yield task.when_any?