@@ -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
+ To reject an update before any events are written to history, throw an exception in a validator. Validators cannot
598
+ be ` async ` , cannot mutate workflow state, and return nothing.
585
599
586
600
#### Running
587
601
@@ -1440,6 +1454,13 @@ to `1` prior to running tests.
1440
1454
Do not commit ` poetry.lock ` or ` pyproject.toml ` changes. To go back from this downgrade, restore ` pyproject.toml ` and
1441
1455
run ` poetry update protobuf grpcio-tools ` .
1442
1456
1457
+ For a less system-intrusive approach, you can:
1458
+ ``` shell
1459
+ docker build -f scripts/_proto/Dockerfile .
1460
+ docker run -v " ${PWD} /temporalio/api:/api_new" -v " ${PWD} /temporalio/bridge/proto:/bridge_new" < just built image sha>
1461
+ poe format
1462
+ ```
1463
+
1443
1464
### Style
1444
1465
1445
1466
* Mostly [ Google Style Guide] ( https://google.github.io/styleguide/pyguide.html ) . Notable exceptions:
0 commit comments