Skip to content

Commit 2c15ed3

Browse files
authored
Workflow Update (#400)
Implementation of the Workflow Update feature
1 parent 97814c2 commit 2c15ed3

25 files changed

+2078
-328
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ temporalio/bridge/target/
66
temporalio/bridge/temporal_sdk_bridge*
77
/tests/helpers/golangserver/golangserver
88
/tests/helpers/golangworker/golangworker
9+
/.idea

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,8 @@ Some things to note about the above code:
458458
#### Definition
459459

460460
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:
463463

464464
```python
465465
import 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+
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.
585599

586600
#### Running
587601

@@ -1440,6 +1454,13 @@ to `1` prior to running tests.
14401454
Do not commit `poetry.lock` or `pyproject.toml` changes. To go back from this downgrade, restore `pyproject.toml` and
14411455
run `poetry update protobuf grpcio-tools`.
14421456

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+
14431464
### Style
14441465

14451466
* Mostly [Google Style Guide](https://google.github.io/styleguide/pyguide.html). Notable exceptions:

scripts/_proto/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM python:3.10
2+
3+
RUN python -m pip install --upgrade wheel "poetry==1.3.2" poethepoet
4+
VOLUME ["/api_new", "/bridge_new"]
5+
6+
COPY ./ ./
7+
8+
RUN mkdir -p ./temporalio/api
9+
RUN poetry install --no-root -E opentelemetry
10+
RUN poetry add "protobuf<4"
11+
RUN poe gen-protos
12+
13+
CMD cp -r ./temporalio/api/* /api_new && cp -r ./temporalio/bridge/proto/* /bridge_new
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.git/
2+
.idea/
3+
.mypy_cache/
4+
.pytest_cache/
5+
.venv/
6+
build/
7+
dist/
8+
temporalio/api/
9+
temporalio/bridge/**/target/
10+
temporalio/bridge/**/*.so
11+
Dockerfile

0 commit comments

Comments
 (0)