Skip to content

Commit 97fed50

Browse files
committed
Feat. Use ctx.state
1 parent a0cebf3 commit 97fed50

3 files changed

Lines changed: 16 additions & 11 deletions

File tree

example/joe.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
Licensed under the Apache License, Version 2.0.
44
"""
55
from domain.domain_pb2 import JoeState, Request, Reply
6-
76
from spawn.eigr.functions.actors.api.actor import Actor
87
from spawn.eigr.functions.actors.api.settings import ActorSettings
98
from spawn.eigr.functions.actors.api.context import Context
@@ -12,15 +11,18 @@
1211
from spawn.eigr.functions.actors.api.workflows.broadcast import Broadcast
1312
from spawn.eigr.functions.actors.api.workflows.effect import Effect
1413

15-
1614
actor = Actor(settings=ActorSettings(name="joe", stateful=True))
1715

1816

1917
@actor.timer_action(every=1000)
2018
def hi(ctx: Context) -> Value:
21-
print("Context {}".format(ctx))
22-
new_state = JoeState()
23-
new_state.languages.append("portuguese")
19+
new_state = None
20+
if not ctx.state:
21+
new_state = JoeState()
22+
new_state.languages.append("portuguese")
23+
else:
24+
new_state = ctx.state
25+
2426
return Value()\
2527
.of("test")\
2628
.state(new_state)\

example/spawn_example.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@
1313
spawn = Spawn()
1414
spawn.port(8091).proxy_port(9003).actor_system(
1515
"spawn-system").add_actor(joe_actor).start()
16-
# spawn.invoke("vijay", "setLanguage", request, Reply)

spawn/eigr/functions/actors/internal/controller.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@
5858

5959

6060
def get_payload(input):
61-
input_type: str = input.payload.type_url
61+
print(input)
62+
input_type: str = input.type_url
6263
if input_type.startswith(TYPE_URL_PREFIX):
6364
input_type = input_type[len(TYPE_URL_PREFIX):]
6465
input_class = _sym_db.GetSymbol(input_type)
65-
input = input_class()
66-
input.ParseFromString(input.payload.value)
67-
return input
66+
result = input_class()
67+
result.ParseFromString(input.value)
68+
return result
6869

6970

7071
def pack(input):
@@ -135,10 +136,13 @@ def handle_invoke(self, data) -> ActorInvocationResponse:
135136
handler = ActorHandler(entity)
136137
current_context = actor_invocation.current_context
137138

139+
state = None if current_context.state == None else get_payload(
140+
current_context.state)
141+
138142
input = None if actor_invocation.WhichOneof(
139143
"payload") == "noop" else get_payload(actor_invocation.value)
140144

141-
ctx = ActorContext(state=None, caller=actor_invocation.caller.name,
145+
ctx = ActorContext(state=state, caller=actor_invocation.caller.name,
142146
metadata=current_context.metadata, tags=current_context.tags)
143147

144148
result = handler.handle_action(

0 commit comments

Comments
 (0)