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

Add Python Tour of Restate #444

Merged
merged 28 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
54e86d9
Add docs/develop/go
jackkleeman Aug 15, 2024
a227806
Update Cloud docs
jackkleeman Aug 15, 2024
cdf3fba
Use main() in service and virtual object
jackkleeman Aug 15, 2024
7070513
Go quickstart
jackkleeman Aug 15, 2024
a39fd74
Update Go SDK
jackkleeman Aug 16, 2024
0926d23
Add tour
jackkleeman Aug 16, 2024
109b345
Small updates
gvdongen Aug 21, 2024
6e55b90
Updates to Tour of Restate Python
gvdongen Aug 22, 2024
35da53f
Tour of Restate Python fixes
gvdongen Aug 22, 2024
956a12f
Update for latest go sdk
jackkleeman Aug 22, 2024
6282c9d
Update docs/develop/go/journaling-results.mdx
jackkleeman Aug 22, 2024
29a8a08
Review comments
jackkleeman Aug 22, 2024
eacec82
github prerelease workflow and fixes for mypy
gvdongen Aug 22, 2024
2ed99a9
Add Python to test-build github workflow
gvdongen Aug 22, 2024
b1ae453
Try bumping Python to 3.12 for github workflows
gvdongen Aug 22, 2024
05d5e71
*string for default check
jackkleeman Aug 22, 2024
08dbb8f
Add go to github workflows
jackkleeman Aug 22, 2024
6be1506
Add logo to overview
jackkleeman Aug 22, 2024
b6800c8
Go in concepts pages
jackkleeman Aug 22, 2024
bb80398
Add go microservice use case
jackkleeman Aug 22, 2024
3e64e5d
Event processing go docs
jackkleeman Aug 22, 2024
4bb79f3
Reduce tab spacing
jackkleeman Aug 22, 2024
0e539bb
Upgrade Python
gvdongen Aug 27, 2024
2ade447
Java formatting
gvdongen Aug 27, 2024
19d8d00
Fix paths to code snippets
gvdongen Aug 27, 2024
a97c09e
Merge branch 'refs/heads/golang' into python_tour
gvdongen Aug 28, 2024
a31e199
Merge branch 'refs/heads/main' into python_tour
gvdongen Sep 9, 2024
912180f
Rebase on main (#453)
gvdongen Sep 9, 2024
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
32 changes: 32 additions & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
description: "sdk-typescript version (without prepending v)."
required: false
type: string
sdkPythonVersion:
description: "sdk-python version (without prepending v)."
required: false
type: string
sdkJavaVersion:
description: "sdk-java version (without prepending v)."
required: false
Expand Down Expand Up @@ -85,6 +89,14 @@ jobs:
field: TYPESCRIPT_SDK_VERSION
value: ${{ inputs.sdkTypescriptVersion }}

- name: Update restate.config.json with new Python sdk version
uses: jossef/[email protected]
if: ${{ inputs.sdkPythonVersion != '' }}
with:
file: restate.config.json
field: PYTHON_SDK_VERSION
value: ${{ inputs.sdkPythonVersion }}

- name: Update restate.config.json with new Java sdk version
uses: jossef/[email protected]
if: ${{ inputs.sdkJavaVersion != '' }}
Expand All @@ -105,6 +117,26 @@ jobs:
- name: Compile TypeScript code snippets
run: npm install --prefix code_snippets/ts && npm run build --prefix code_snippets/ts

# Upgrade Python code snippets if new version is provided
- name: Upgrade Python Restate SDK
if: github.event.inputs.sdkPythonVersion != ''
run: sed -i 's/restate_sdk==[0-9A-Za-z.-]*/restate_sdk=="${{ inputs.sdkPythonVersion }}"/' "code_snippets/python/requirements.txt"

# Test if Python code snippets compile
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies and check Python code snippets
run: |
cd code_snippets/python
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install mypy
python3 -m mypy .
deactivate

# Upgrade Java code snippets if new version is provided
- name: Find and replace restateVersion in build.gradle.kts for Java code snippets
if: ${{ inputs.sdkJavaVersion != '' }}
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ jobs:
exit 1
fi


# Setup Python
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

# Test if Python code snippets compile
- name: Install dependencies and check Python code snippets
run: |
cd code_snippets/python
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install mypy
python3 -m mypy .
deactivate

# Setup Java
- uses: actions/setup-java@v3
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ yarn-error.log*
.yarn
/code_snippets/ts/node_modules/
/code_snippets/ts/dist/
/code_snippets/python/venv/
49 changes: 49 additions & 0 deletions code_snippets/go/develop/awakeable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package develop

import (
"fmt"

restate "github.com/restatedev/sdk-go"
)

type Awakeable struct{}

func (Awakeable) Greet(ctx restate.Context, name string) (restate.Void, error) {
// <start_here>
// <mark_1>
awakeable := restate.AwakeableAs[string](ctx)
awakeableId := awakeable.Id()
// </mark_1>

// <mark_2>
restate.RunAs(ctx, func(ctx restate.RunContext) (string, error) {
return triggerTaskAndDeliverId(awakeableId)
})
// </mark_2>

// <mark_3>
payload, err := awakeable.Result()
if err != nil {
return restate.Void{}, err
}
// </mark_3>
// <end_here>

_ = payload

// <start_resolve>
if err := ctx.ResolveAwakeable(awakeableId, "hello"); err != nil {
return restate.Void{}, err
}
// <end_resolve>

// <start_reject>
ctx.RejectAwakeable(awakeableId, fmt.Errorf("my error reason"))
// <end_reject>

return restate.Void{}, nil
}

func triggerTaskAndDeliverId(awakeableId string) (string, error) {
return "123", nil
}
58 changes: 58 additions & 0 deletions code_snippets/go/develop/codegen/codegen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package main

import (
"context"
"fmt"
"log"

"github.com/restatedev/documentation/code_snippets/go/develop/codegen/proto"
restate "github.com/restatedev/sdk-go"
"github.com/restatedev/sdk-go/server"
)

// <start_server>
type greeter struct {
proto.UnimplementedGreeterServer
}

func (greeter) SayHello(ctx restate.Context, req *proto.HelloRequest) (*proto.HelloResponse, error) {
return &proto.HelloResponse{
Message: fmt.Sprintf("%s!", req.Name),
}, nil
}

func main() {
if err := server.NewRestate().
Bind(proto.NewGreeterServer(greeter{})).
Start(context.Background(), ":9080"); err != nil {
log.Fatal(err)
}
}

// <end_server>

type GreeterClient struct{}

func (GreeterClient) CallGreeter(ctx restate.Context, _ restate.Void) (restate.Void, error) {
// <start_client>
client := proto.NewGreeterClient(ctx)
resp, err := client.SayHello().Request(&proto.HelloRequest{Name: "world"})
if err != nil {
return restate.Void{}, err
}
// <end_client>
_ = resp

{
// <start_virtual_object_client>
client := proto.NewCounterClient(ctx, "key-1")
resp, err := client.Add().Request(&proto.AddRequest{Delta: 1})
if err != nil {
return restate.Void{}, err
}
// <end_virtual_object_client>
_ = resp
}

return restate.Void{}, nil
}
Loading
Loading