-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f84ddf1
commit 11e8b46
Showing
16 changed files
with
7,387 additions
and
54 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
default_context: | ||
elixir_version: "1.14" | ||
app_name: spawn_example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,4 @@ | ||
{ | ||
"elixir_version": [ | ||
"1.14", | ||
"1.15", | ||
"1.16" | ||
], | ||
"app_name": "elixir_sdk_example", | ||
"app_name_hyphenate": "elixir_sdk_example", | ||
"app_description": "Spawn App.", | ||
"app_image_tag": "eigr/spawn-elixir-example:1.4.1", | ||
"app_port": 8090, | ||
"app_module_name": "ElixirSdkExample", | ||
"spawn_app_spawm_system": "spawn-system", | ||
"spawn_app_namespace": "default", | ||
"spawn_app_statestore_type": "Postgres", | ||
"spawn_sdk_version": "1.14", | ||
"_copy_without_render": [ | ||
".github", | ||
"docs", | ||
".dockerignore", | ||
".gitignore", | ||
".envrc", | ||
".formatter.exs" | ||
] | ||
"app_name": "spawn_example", | ||
"spawn_system": "spawn-system" | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# {{ cookiecutter.app_name }} | ||
|
||
This is a [Spawn](https://github.com/eigr/spawn) app | ||
|
||
# Running in dev mode | ||
|
||
Make sure the proxy is running with: | ||
|
||
``` | ||
spawn dev run -p ./protos -s {{ cookiecutter.spawn_system }} -W | ||
``` | ||
|
||
Run your application with: | ||
|
||
``` | ||
yarn start | ||
``` | ||
|
||
### Invoking your Actor | ||
|
||
You can now invoke your Actor with: | ||
|
||
``` | ||
curl -vvv -H 'Accept: application/json' http://localhost:9980/v1/hello_world?message=World | ||
``` | ||
|
||
> **NOTE**: This uses the HTTP transcoding from the protobuf definition, you can also invoke this actor from other Spawn hosts. | ||
# Setup for production | ||
|
||
``` | ||
spawn new prod | ||
``` | ||
|
||
# Documentation | ||
|
||
See [SDK Documentation](https://github.com/eigr/spawn-node-sdk/tree/main?tab=readme-ov-file#documentation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import spawn, { Kind } from '@eigr/spawn-sdk' | ||
import { | ||
HelloWorldActorState, | ||
SayHelloRequest, | ||
SayHelloResponse | ||
} from './src/generated/actors/hello' | ||
import { sayHelloHandler } from './src/hello_world_actor_handler' | ||
|
||
const system = spawn.createSystem('{{ cookiecutter.spawn_system }}') | ||
|
||
const actor = system.buildActor({ | ||
name: 'HelloWorldActor', | ||
kind: Kind.NAMED, | ||
stateType: HelloWorldActorState, | ||
stateful: true, | ||
snapshotTimeout: 5_000n, | ||
deactivatedTimeout: 10_000n | ||
}) | ||
|
||
actor.addAction( | ||
{ name: 'SayHello', payloadType: SayHelloRequest, responseType: SayHelloResponse }, | ||
sayHelloHandler | ||
) | ||
|
||
system.register().then(() => { | ||
console.log('[SpawnSystem] Actors registered successfully') | ||
|
||
console.debug( | ||
'[SpawnSystem] [debug] Make sure to run the Spawn Proxy with the `spawnctl dev run` command' | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "{{ cookiecutter.app_name }}", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@eigr/spawn-sdk": "^1.2.0" | ||
}, | ||
"devDependencies": { | ||
"tsx": "^4.16.2" | ||
}, | ||
"scripts": { | ||
"build-protos": "protoc --ts_out ./src/generated/ --ts_opt force_client_none,force_server_none --proto_path ./protos/ ./protos/**/**/*.proto ./protos/**/*.proto", | ||
"start": "yarn build-protos && tsx index.ts", | ||
"start-bun": "yarn build-protos && bun run index.ts" | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
nodejs/{{cookiecutter.app_name}}/protos/actors/hello.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
syntax = "proto3"; | ||
|
||
import "google/protobuf/descriptor.proto"; | ||
import "google/api/annotations.proto"; | ||
|
||
service HelloWorldActor { | ||
rpc SayHello(SayHelloRequest) returns (SayHelloResponse) { | ||
option (google.api.http) = { | ||
get: "/v1/hello_world" | ||
}; | ||
} | ||
} | ||
|
||
message HelloWorldActorState { | ||
int32 times = 1; | ||
string last_message = 2; | ||
} | ||
|
||
message SayHelloRequest { | ||
string message = 1; | ||
} | ||
|
||
message SayHelloResponse { | ||
string response = 1; | ||
} | ||
|
31 changes: 31 additions & 0 deletions
31
nodejs/{{cookiecutter.app_name}}/protos/google/api/annotations.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
syntax = "proto3"; | ||
|
||
package google.api; | ||
|
||
import "google/api/http.proto"; | ||
import "google/protobuf/descriptor.proto"; | ||
|
||
option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; | ||
option java_multiple_files = true; | ||
option java_outer_classname = "AnnotationsProto"; | ||
option java_package = "com.google.api"; | ||
option objc_class_prefix = "GAPI"; | ||
|
||
extend google.protobuf.MethodOptions { | ||
// See `HttpRule`. | ||
HttpRule http = 72295728; | ||
} |
Oops, something went wrong.