Skip to content

Commit

Permalink
Workflow Update (#400)
Browse files Browse the repository at this point in the history
Implementation of the Workflow Update feature
  • Loading branch information
Sushisource authored Oct 25, 2023
1 parent 97814c2 commit 2c15ed3
Show file tree
Hide file tree
Showing 25 changed files with 2,078 additions and 328 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ temporalio/bridge/target/
temporalio/bridge/temporal_sdk_bridge*
/tests/helpers/golangserver/golangserver
/tests/helpers/golangworker/golangworker
/.idea
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,8 @@ Some things to note about the above code:
#### Definition

Workflows are defined as classes decorated with `@workflow.defn`. The method invoked for the workflow is decorated with
`@workflow.run`. Methods for signals and queries are decorated with `@workflow.signal` and `@workflow.query`
respectively. Here's an example of a workflow:
`@workflow.run`. Methods for signals, queries, and updates are decorated with `@workflow.signal`, `@workflow.query`
and `@workflow.update` respectively. Here's an example of a workflow:

```python
import asyncio
Expand Down Expand Up @@ -515,6 +515,12 @@ class GreetingWorkflow:
@workflow.query
def current_greeting(self) -> str:
return self._current_greeting

@workflow.update
def set_and_get_greeting(self, greeting: str) -> str:
old = self._current_greeting
self._current_greeting = greeting
return old

```

Expand Down Expand Up @@ -582,6 +588,14 @@ Here are the decorators that can be applied:
* All the same constraints as `@workflow.signal` but should return a value
* Should not be `async`
* Temporal queries should never mutate anything in the workflow or call any calls that would mutate the workflow
* `@workflow.update` - Defines a method as an update
* May both accept as input and return a value
* May be `async` or non-`async`
* May mutate workflow state, and make calls to other workflow APIs like starting activities, etc.
* Also accepts the `name` and `dynamic` parameters like signals and queries, with the same semantics.
* Update handlers may optionally define a validator method by decorating it with `@update_handler_method.validator`.
To reject an update before any events are written to history, throw an exception in a validator. Validators cannot
be `async`, cannot mutate workflow state, and return nothing.

#### Running

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

For a less system-intrusive approach, you can:
```shell
docker build -f scripts/_proto/Dockerfile .
docker run -v "${PWD}/temporalio/api:/api_new" -v "${PWD}/temporalio/bridge/proto:/bridge_new" <just built image sha>
poe format
```

### Style

* Mostly [Google Style Guide](https://google.github.io/styleguide/pyguide.html). Notable exceptions:
Expand Down
13 changes: 13 additions & 0 deletions scripts/_proto/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.10

RUN python -m pip install --upgrade wheel "poetry==1.3.2" poethepoet
VOLUME ["/api_new", "/bridge_new"]

COPY ./ ./

RUN mkdir -p ./temporalio/api
RUN poetry install --no-root -E opentelemetry
RUN poetry add "protobuf<4"
RUN poe gen-protos

CMD cp -r ./temporalio/api/* /api_new && cp -r ./temporalio/bridge/proto/* /bridge_new
11 changes: 11 additions & 0 deletions scripts/_proto/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.git/
.idea/
.mypy_cache/
.pytest_cache/
.venv/
build/
dist/
temporalio/api/
temporalio/bridge/**/target/
temporalio/bridge/**/*.so
Dockerfile
Loading

0 comments on commit 2c15ed3

Please sign in to comment.