88from typing import MutableMapping
99
1010from spawn .eigr .functions .actors .api .actor import Actor
11+ from spawn .eigr .functions .actors .api .reference import ActorRef
12+ from spawn .eigr .functions .actors .internal .client import SpawnClient
1113from spawn .eigr .functions .actors .internal .controller import ActorController
1214
1315from google .protobuf .any_pb2 import Any as ProtoAny
@@ -24,6 +26,7 @@ def create_app(controller: ActorController):
2426
2527 @app .route ('/api/v1/actors/actions' , methods = ["POST" ])
2628 def action ():
29+ print (request )
2730 data = request .data
2831
2932 actor_invocation_response = controller .handle_invoke (data )
@@ -54,31 +57,33 @@ class Spawn:
5457 __actor_entities : MutableMapping [str ,
5558 Actor ] = field (default_factory = dict )
5659
57- # @staticmethod
58- # def invoke(name: str, command: str, arg: Any, output_type: Any) -> Any:
59- # actorController = ActorController(
60- # os.environ.get("PROXY_HOST", "localhost"),
61- # os.environ.get("PROXY_PORT", "9002"),
62- # )
63- # actorController.invoke(name, command, arg, output_type)
60+ @staticmethod
61+ def create_actor_ref (system : str , actor_name : str , parent : str = None , state_revision : int = None ) -> ActorRef :
62+ client = SpawnClient ()
63+ return ActorRef (client , system , actor_name , parent , state_revision )
6464
6565 def host (self , address : str ):
6666 """Set the Network Host address."""
6767 self .__host = address
68+ os .environ ["USER_FUNCTION_HOST" ] = address
6869 return self
6970
7071 def port (self , port : int ):
7172 """Set the Network Port address."""
7273 self .__port = port
74+ os .environ ["USER_FUNCTION_PORT" ] = str (port )
7375 return self
7476
7577 def proxy_host (self , host : str ):
7678 """Set the Spawn Proxy Host Address"""
7779 self .__proxy_host = host
80+ os .environ ["PROXY_HTTP_HOST" ] = host
7881 return self
7982
8083 def proxy_port (self , port : int ):
81- self .__proxy_port = str (port )
84+ port_str : str = str (port )
85+ self .__proxy_port = port_str
86+ os .environ ["PROXY_HTTP_PORT" ] = port_str
8287 return self
8388
8489 def actor_system (self , system : str = None ):
@@ -93,13 +98,16 @@ def add_actor(self, actor: Actor):
9398
9499 def start (self ):
95100 """Start the user function and HTTP Server."""
101+ import time
96102 if not self .__system :
97103 raise Exception (
98104 "ActorSystem cannot be None. Use actor_system function to set an ActorSystem" )
99105
100106 address = "{}:{}" .format (self .__host , self .__port )
107+ client = SpawnClient ()
108+
101109 self .__controller = ActorController (
102- self . __proxy_host , self . __proxy_port , self .__system , self .__actor_entities )
110+ client , self .__system , self .__actor_entities )
103111
104112 self .__app = create_app (controller = self .__controller )
105113
@@ -111,8 +119,8 @@ def start(self):
111119 try :
112120 server .start ()
113121 client .start ()
114- server . join ()
115- client . join ( )
122+ # temporary
123+ time . sleep ( 2 )
116124 except IOError as e :
117125 logging .error ("Error on start Spawn %s" , e .__cause__ )
118126
0 commit comments