@@ -458,8 +458,8 @@ Some things to note about the above code:
458458#### Definition
459459
460460Workflows are defined as classes decorated with ` @workflow.defn ` . The method invoked for the workflow is decorated with
461- ` @workflow.run ` . Methods for signals and queries are decorated with ` @workflow.signal ` and ` @workflow.query `
462- respectively. Here's an example of a workflow:
461+ ` @workflow.run ` . Methods for signals, queries, and updates are decorated with ` @workflow.signal ` , ` @workflow.query `
462+ and ` @workflow.update ` respectively. Here's an example of a workflow:
463463
464464``` python
465465import asyncio
@@ -515,6 +515,12 @@ class GreetingWorkflow:
515515 @workflow.query
516516 def current_greeting (self ) -> str :
517517 return self ._current_greeting
518+
519+ @workflow.update
520+ def set_and_get_greeting (self , greeting : str ) -> str :
521+ old = self ._current_greeting
522+ self ._current_greeting = greeting
523+ return old
518524
519525```
520526
@@ -582,6 +588,14 @@ Here are the decorators that can be applied:
582588 * All the same constraints as ` @workflow.signal ` but should return a value
583589 * Should not be ` async `
584590 * Temporal queries should never mutate anything in the workflow or call any calls that would mutate the workflow
591+ * ` @workflow.update ` - Defines a method as an update
592+ * May both accept as input and return a value
593+ * May be ` async ` or non-` async `
594+ * May mutate workflow state, and make calls to other workflow APIs like starting activities, etc.
595+ * Also accepts the ` name ` and ` dynamic ` parameters like signals and queries, with the same semantics.
596+ * Update handlers may optionally define a validator method by decorating it with ` @update_handler_method.validator ` .
597+ Validators cannot be ` async ` , cannot mutate workflow state, and return nothing. They can be used to reject update
598+ calls before any events are written to history by throwing an exception.
585599
586600#### Running
587601
0 commit comments