|
2 | 2 | Python User Language Support for [Spawn](https://github.com/eigr/spawn). |
3 | 3 |
|
4 | 4 | # Table of Contents |
| 5 | + |
5 | 6 | 1. [Overview](#overview) |
6 | 7 | 2. [Getting Started](#getting-started) |
| 8 | +3. [Advanced Use Cases](#advanced-use-cases) |
| 9 | + - [Side Effects](#side-effects) |
| 10 | + - [Broadcast](#broadcast) |
| 11 | + - [Forward](#forward) |
| 12 | + - [Pipe](#pipe) |
| 13 | +4. [Deploy](#deploy) |
| 14 | + - [Packing with Containers](#packing-with-containers) |
| 15 | + - [Defining an ActorSytem](#defining-an-actorsytem) |
| 16 | + - [Defining an ActorHost](#defining-an-actorhost) |
7 | 17 |
|
8 | 18 |
|
9 | 19 | ## Overview |
@@ -92,6 +102,60 @@ actor = Actor(settings=ActorSettings( |
92 | 102 | name="joe", stateful=True, channel="test")) |
93 | 103 |
|
94 | 104 |
|
| 105 | +@actor.timer_action(every=1000) |
| 106 | +def hi(ctx: Context) -> Value: |
| 107 | + new_state = None |
| 108 | + |
| 109 | + if not ctx.state: |
| 110 | + new_state = JoeState() |
| 111 | + new_state.languages.append("python") |
| 112 | + else: |
| 113 | + new_state = ctx.state |
| 114 | + |
| 115 | + return Value().state(new_state).noreply() |
| 116 | +``` |
| 117 | + |
| 118 | +Now with our Actor properly defined, we just need to start the SDK correctly. Create another file called main.py to serve as your application's entrypoint and fill it with the following content: |
| 119 | + |
| 120 | +```python |
| 121 | +from spawn.eigr.functions.actors.api.sdk import Spawn |
| 122 | +from joe import actor as joe_actor |
| 123 | + |
| 124 | +if __name__ == "__main__": |
| 125 | + spawn = Spawn() |
| 126 | + spawn.port(8091).proxy_port(9003).actor_system( |
| 127 | + "spawn-system").add_actor(joe_actor).start() |
| 128 | +``` |
| 129 | + |
| 130 | +Then: |
| 131 | + |
| 132 | +```shell |
| 133 | +poetry run python3 spawn_py_demo/main.py |
| 134 | +``` |
| 135 | + |
| 136 | +And this is it to start! Now that you know the basics of local development, we can go a little further. |
| 137 | + |
| 138 | +## Advanced Use Cases |
| 139 | +TODO |
| 140 | + |
| 141 | +### Side Effects |
| 142 | +TODO |
| 143 | + |
| 144 | +### Broadcast |
| 145 | +TODO |
| 146 | + |
| 147 | +```python |
| 148 | +from domain.domain_pb2 import JoeState, Request, Reply |
| 149 | +from spawn.eigr.functions.actors.api.actor import Actor |
| 150 | +from spawn.eigr.functions.actors.api.settings import ActorSettings |
| 151 | +from spawn.eigr.functions.actors.api.context import Context |
| 152 | +from spawn.eigr.functions.actors.api.value import Value |
| 153 | +from spawn.eigr.functions.actors.api.workflows.broadcast import Broadcast |
| 154 | + |
| 155 | +actor = Actor(settings=ActorSettings( |
| 156 | + name="joe", stateful=True, channel="test")) |
| 157 | + |
| 158 | + |
95 | 159 | @actor.timer_action(every=1000) |
96 | 160 | def hi(ctx: Context) -> Value: |
97 | 161 | new_state = None |
@@ -121,14 +185,21 @@ def set_language(request: Request, ctx: Context) -> Value: |
121 | 185 | return Value().of(reply, ctx.state).reply() |
122 | 186 | ``` |
123 | 187 |
|
124 | | -Now with our Actor properly defined, we just need to start the SDK correctly. Create another file to serve as your application's entrypoint and fill it with the following content: |
| 188 | +### Forward |
| 189 | +TODO |
125 | 190 |
|
126 | | -```python |
127 | | -from spawn.eigr.functions.actors.api.sdk import Spawn |
128 | | -from joe import actor as joe_actor |
| 191 | +### Pipe |
| 192 | +TODO |
129 | 193 |
|
130 | | -if __name__ == "__main__": |
131 | | - spawn = Spawn() |
132 | | - spawn.port(8091).proxy_port(9003).actor_system( |
133 | | - "spawn-system").add_actor(joe_actor).start() |
134 | | -``` |
| 194 | +## Deploy |
| 195 | +TODO |
| 196 | + |
| 197 | +### Packing with Containers |
| 198 | +TODO |
| 199 | + |
| 200 | +### Defining an ActorSytem |
| 201 | +TODO |
| 202 | + |
| 203 | +### Defining an ActorHost |
| 204 | +TODO |
| 205 | + |
0 commit comments