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

New quickstart #214

Merged
merged 23 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
11 changes: 5 additions & 6 deletions templates/python/example.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import uuid
import restate
from datetime import timedelta

from restate import Service, Context
import restate

from pydantic_models import GreetingRequest, Greeting
from utils import send_notification, send_reminder

greeter = Service("Greeter")


@greeter.handler()
async def greet(ctx: Context, name: str) -> str:
async def greet(ctx: Context, req: GreetingRequest) -> Greeting:
# Durably execute a set of steps; resilient against failures
greeting_id = await ctx.run("generate UUID", lambda: str(uuid.uuid4()))
gvdongen marked this conversation as resolved.
Show resolved Hide resolved
await ctx.run("send notification", lambda: send_notification(greeting_id, name))
await ctx.run("send notification", lambda: send_notification(greeting_id, req.name))
await ctx.sleep(timedelta(seconds=1))
await ctx.run("send reminder", lambda: send_reminder(greeting_id))

# Respond to caller
return f"You said hi to {name}!"
return Greeting(message=f"You said hi to {req.name}!")

app = restate.app(services=[greeter])
12 changes: 12 additions & 0 deletions templates/python/pydantic_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# You can remove this file.
# It's only purpose is providing pydantic models for the template.
from pydantic import BaseModel


# You can also just use a typed dict, without Pydantic
class GreetingRequest(BaseModel):
name: str


class Greeting(BaseModel):
message: str
Comment on lines +7 to +12
Copy link
Contributor

Choose a reason for hiding this comment

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

I would honestly have them in example.py, makes the whole thing way more readable, and this is super small...

3 changes: 2 additions & 1 deletion templates/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
hypercorn
restate_sdk==0.4.1
restate_sdk==0.4.1
pydantic