@@ -458,8 +458,8 @@ Some things to note about the above code:
458
458
#### Definition
459
459
460
460
Workflows 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:
463
463
464
464
``` python
465
465
import asyncio
@@ -515,6 +515,12 @@ class GreetingWorkflow:
515
515
@workflow.query
516
516
def current_greeting (self ) -> str :
517
517
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
518
524
519
525
```
520
526
@@ -582,6 +588,14 @@ Here are the decorators that can be applied:
582
588
* All the same constraints as ` @workflow.signal ` but should return a value
583
589
* Should not be ` async `
584
590
* 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.
585
599
586
600
#### Running
587
601
0 commit comments