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 web frontend to hello-world example #8

Merged
merged 4 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 20 additions & 2 deletions .rsmrc
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,23 @@ dev:hello-constructors --env=PYTHONPATH=api/
# Tell `rsm` that this is a Python application.
dev:hello-constructors --python

# Run this application!
dev:hello-constructors hello-constructors/backend/src/main.py
# Run hello-constructors application!
dev:hello-constructors hello-constructors/backend/src/main.py

# Watch if any generated files are modified.
dev:hello-world --watch=api/**/*.py

# Watch if any of our source files are modified.
dev:hello-world --watch=hello-world/backend/src/**/*.py

# PYTHONPATH must be explicitly set to pick up generated code.
dev:hello-world --env=PYTHONPATH=api/

# Tell `rsm` that this is a Python application.
dev:hello-world --python

# Save state between chaos restarts.
dev:hello-world --name=hello-world

# Run hello-world application!
dev:hello-world hello-world/backend/src/main.py
21 changes: 10 additions & 11 deletions api/hello_world/v1/greeter.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,31 @@ import "resemble/v1alpha1/options.proto";
service Greeter {
option (resemble.v1alpha1.service).state = "GreeterState";

rpc Create(CreateRequest) returns (CreateResponse) {
option (resemble.v1alpha1.method).writer = {
constructor: true,
rpc Greetings(GreetingsRequest) returns (GreetingsResponse) {
rileysdev marked this conversation as resolved.
Show resolved Hide resolved
option (resemble.v1alpha1.method).reader = {
};
}

rpc Greet(GreetRequest) returns (GreetResponse) {
option (resemble.v1alpha1.method).reader = {
option (resemble.v1alpha1.method).writer = {
};
}
}

message GreeterState {
string greeting = 1;
repeated string greetings = 2;
}

message CreateRequest {
string greeting = 1; // E.g. "Hello".
}
message GreetingsRequest {}

message CreateResponse {}
message GreetingsResponse {
repeated string greetings = 1;
}

message GreetRequest {
string name = 1; // E.g. "World".
string greeting = 1; // E.g. "Hello, World".
}

message GreetResponse {
string message = 1; // E.g. "Hello, World!".
string greeting = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really see the purpose of Greet returning the same greeting that was sent in the request? Can we just remove this field from the response?

Copy link
Contributor

Choose a reason for hiding this comment

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

@sp33drac3r it seems like the comments in this file were resolved, but the changes weren't made? How come?

}
2 changes: 1 addition & 1 deletion hello-constructors/backend/src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
reboot-resemble>=0.0.5
reboot-resemble>=0.0.6
pytest>=7.4.2
28 changes: 14 additions & 14 deletions hello-world/backend/src/greeter_servicer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import asyncio
from hello_world.v1.greeter_rsm import (
CreateRequest,
CreateResponse,
Greeter,
GreeterState,
GreetingsRequest,
GreetingsResponse,
GreetRequest,
GreetResponse,
)
Expand All @@ -12,20 +12,20 @@

class GreeterServicer(Greeter.Interface):

async def Create(
self,
context: WriterContext,
request: CreateRequest,
) -> Greeter.CreateEffects:
return Greeter.CreateEffects(
state=GreeterState(greeting=request.greeting),
response=CreateResponse()
)
async def Greetings(
self, context: ReaderContext, state: GreeterState,
request: GreetingsRequest
) -> GreetingsResponse:
return GreetingsResponse(greetings=state.greetings)

async def Greet(
self,
context: ReaderContext,
context: WriterContext,
state: GreeterState,
request: GreetRequest,
) -> GreetResponse:
return GreetResponse(message=f"{state.greeting}, {request.name}")
) -> Greeter.GreetEffects:
greeting = request.greeting
state.greetings.extend([greeting])
rileysdev marked this conversation as resolved.
Show resolved Hide resolved
return Greeter.GreetEffects(
state=state, response=GreetResponse(greeting=greeting)
)
12 changes: 1 addition & 11 deletions hello-world/backend/src/main.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import asyncio
import logging
from hello_world.v1.greeter_rsm import Greeter, GreetResponse
from greeter_servicer import GreeterServicer
from resemble.aio.applications import Application
from resemble.aio.workflows import Workflow

logging.basicConfig(level=logging.INFO)

EXAMPLE_GREETER_ID = 'my-cool-greeter'


async def initialize(workflow: Workflow):
greeter = Greeter(EXAMPLE_GREETER_ID)

# Create the state machine.
await greeter.Create(workflow, greeting="Hello")

# Demonstrate that we can use the actor.
response: GreetResponse = await greeter.Greet(workflow, name="World")
logging.info(f"Received a greeting: '{response.message}'")
logging.info(f"Greeter is ready... Try recording a greeting!")


async def main():
Expand Down
2 changes: 1 addition & 1 deletion hello-world/backend/src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
reboot-resemble>=0.0.5
reboot-resemble>=0.0.6
pytest>=7.4.2
23 changes: 23 additions & 0 deletions hello-world/web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
16 changes: 16 additions & 0 deletions hello-world/web/config-overrides.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { removeModuleScopePlugin, override, babelInclude } = require("customize-cra");
const path = require("path");

module.exports = function (config, env) {

return Object.assign(
config,
override(
removeModuleScopePlugin(),
babelInclude([
path.resolve('src'),
path.resolve('../../api/hello_world/v1'),
])
)(config, env)
)
}
Loading
Loading