@@ -24,18 +24,20 @@ class ApproveInput:
2424@workflow .defn
2525class GreetingWorkflow :
2626 """
27- A workflow that that returns a greeting in one of two languages.
28-
29- It supports a Query to obtain the current language, an Update to change the
30- current language and receive the previous language in response, and a Signal
31- to approve the Workflow so that it is allowed to return its result.
27+ A workflow that that returns a greeting in one of multiple supported
28+ languages.
29+
30+ It exposes a query to obtain the current language, a signal to approve the
31+ workflow so that it is allowed to return its result, and two updates for
32+ changing the current language and receiving the previous language in
33+ response.
34+
35+ One of the update handlers is not an `async def`, so it can only mutate and
36+ return local workflow state; the other update handler is `async def` and
37+ executes an activity which calls a remote service, giving access to language
38+ translations which are not available in local workflow state.
3239 """
3340
34- # 👉 This Workflow does not use any async handlers and so cannot use any
35- # Activities. It only supports two languages, whose greetings are hardcoded
36- # in the Workflow definition. See GreetingWorkflowWithAsyncHandler below for
37- # a Workflow that uses an async Update handler to call an Activity.
38-
3941 def __init__ (self ) -> None :
4042 self .approved_for_release = False
4143 self .approver_name : Optional [str ] = None
@@ -97,12 +99,14 @@ async def set_language_using_activity(self, language: Language) -> Language:
9799 language ,
98100 start_to_close_timeout = timedelta (seconds = 10 ),
99101 )
102+ # 👉 The requested language might not be supported by the remote
103+ # service. If so, we raise ApplicationError, which will fail the
104+ # Update. The WorkflowExecutionUpdateAccepted event will still
105+ # be added to history. (Update validators can be used to reject
106+ # updates before any event is written to history, but they
107+ # cannot be async, and so we cannot use an update validator for
108+ # this purpose.)
100109 if greeting is None :
101- # 👉 An update validator cannot be async, so cannot be used
102- # to check that the remote call_greeting_service supports
103- # the requested language. Raising ApplicationError will fail
104- # the Update, but the WorkflowExecutionUpdateAccepted event
105- # will still be added to history.
106110 raise ApplicationError (
107111 f"Greeting service does not support { language .name } "
108112 )
0 commit comments