Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflow Update #400

Merged
merged 29 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e839219
Update Core
Sushisource Oct 11, 2023
cf7cc9b
Add docker image for proto building
Sushisource Oct 11, 2023
2b0d6f0
Basic happy path working
Sushisource Oct 12, 2023
c2281c5
Validator running
Sushisource Oct 13, 2023
84b909c
Add UpdateHandle. Polling not yet implemented.
Sushisource Oct 13, 2023
d1e0681
Add polling
Sushisource Oct 16, 2023
713c847
Linting / mypy
Sushisource Oct 16, 2023
abe36c3
Update core / additional failure path tests
Sushisource Oct 17, 2023
533b9f7
Dynamic update handlers
Sushisource Oct 17, 2023
5daec88
Use class for update decorator
Sushisource Oct 17, 2023
668532d
Add update definitions to workflow definition test
Sushisource Oct 17, 2023
3a9dc2c
Finally! Type system defeated!
Sushisource Oct 19, 2023
6a7c52a
Rename update to execute_update and hide wait_for_stage param
Sushisource Oct 19, 2023
4be97cc
Always run validator interceptor
Sushisource Oct 20, 2023
953b8e4
Clean up some last TODOs / workflow definition error tests
Sushisource Oct 20, 2023
2e54df6
3.7 throws this error differently
Sushisource Oct 20, 2023
188bf97
Update README
Sushisource Oct 20, 2023
03e3197
Skip updates in Java test server for now
Sushisource Oct 21, 2023
cc0871d
Make validator interceptor sync
Sushisource Oct 23, 2023
de98531
Address various review comments
Sushisource Oct 23, 2023
afc1807
Update core & add inbound tracing interceptor
Sushisource Oct 24, 2023
8b41042
Make sure only temporal errors fail update during handler
Sushisource Oct 24, 2023
5d2b614
Merge branch 'main' into workflow-update
Sushisource Oct 24, 2023
6b0972d
Renames / no poll update tracing
Sushisource Oct 24, 2023
020f663
Add start_update overloads / update handle type
Sushisource Oct 24, 2023
6670ee5
Ensure otel test will wait until after task fails to send update
Sushisource Oct 25, 2023
1731fcf
Latest review comments
Sushisource Oct 25, 2023
1c18fc2
Fix failure setting on update rejection
Sushisource Oct 25, 2023
fabaecf
Merge branch 'main' into workflow-update
Sushisource Oct 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrmm, I wonder if just altering update_salutation to be an update that return the previous salutation part would be enough. Also, I wonder if calling this update_greeting is descriptive enough. I don't think it matters much. But I will take the approach of return-old-thing in the .NET PR.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* May mutate workflow state, and make calls to other workflow APIs like starting activities, etc.
* May mutate workflow state, make calls to other workflow APIs like starting activities, etc.

(pedantic, can ignore)

* 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
Loading