File tree Expand file tree Collapse file tree
spawn/eigr/functions/actors/internal Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33Licensed under the Apache License, Version 2.0.
44"""
55from domain .domain_pb2 import JoeState , Request , Reply
6-
76from spawn .eigr .functions .actors .api .actor import Actor
87from spawn .eigr .functions .actors .api .settings import ActorSettings
98from spawn .eigr .functions .actors .api .context import Context
1211from spawn .eigr .functions .actors .api .workflows .broadcast import Broadcast
1312from spawn .eigr .functions .actors .api .workflows .effect import Effect
1413
15-
1614actor = Actor (settings = ActorSettings (name = "joe" , stateful = True ))
1715
1816
1917@actor .timer_action (every = 1000 )
2018def 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 )\
Original file line number Diff line number Diff line change 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)
Original file line number Diff line number Diff line change 5858
5959
6060def 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
7071def 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 (
You can’t perform that action at this time.
0 commit comments