22Copyright 2022 Eigr.
33Licensed under the Apache License, Version 2.0.
44"""
5- from spawn .eigr .actor_pb2 import Actor , ActorDeactivateStrategy , ActorSnapshotStrategy , ActorState , ActorSystem , Registry , TimeoutStrategy
6- from spawn .eigr .protocol_pb2 import RegistrationRequest , RegistrationResponse , ServiceInfo
5+ from spawn .eigr .actor_pb2 import (
6+ Actor ,
7+ ActorDeactivateStrategy ,
8+ ActorSnapshotStrategy ,
9+ ActorState ,
10+ ActorSystem ,
11+ Registry ,
12+ TimeoutStrategy ,
13+ )
14+ from spawn .eigr .protocol_pb2 import (
15+ RegistrationRequest ,
16+ RegistrationResponse ,
17+ ServiceInfo ,
18+ )
719
820from spawn .entity import ActorEntity
921
1628
1729class SpawnActorController :
1830
19- register_uri = ' /api/v1/system'
31+ register_uri = " /api/v1/system"
2032
2133 default_headers = {
2234 "Accept" : "application/octet-stream" ,
23- "Content-Type" : "application/octet-stream"
35+ "Content-Type" : "application/octet-stream" ,
2436 }
2537
2638 def __init__ (self , host : str , port : str ):
2739 self .host = host
2840 self .port = port
2941
30- def invoke (self , actor_name : str , actor_command : str , arg : Any , output_type : Any ) -> Any :
42+ def invoke (
43+ self , actor_name : str , actor_command : str , arg : Any , output_type : Any
44+ ) -> Any :
3145 return ""
3246
3347 def register (self , actors : List [ActorEntity ]):
34- logging .info (' Registering Actors on the Proxy %s' , actors )
48+ logging .info (" Registering Actors on the Proxy %s" , actors )
3549 try :
3650
37- proxy_url = ' http://{}:{}{}' .format (self .host , self .port , self .register_uri )
51+ proxy_url = " http://{}:{}{}" .format (self .host , self .port , self .register_uri )
3852
3953 # Create actor params via ActorEntity
4054 deactivate_timeout_strategy = TimeoutStrategy ()
@@ -46,7 +60,7 @@ def register(self, actors: List[ActorEntity]):
4660 actor_state = ActorState ()
4761
4862 deactivate_strategy = ActorDeactivateStrategy ()
49- deactivate_strategy .timeout .CopyFrom (deactivate_timeout_strategy )
63+ deactivate_strategy .timeout .CopyFrom (deactivate_timeout_strategy )
5064
5165 snaphot_strategy = ActorSnapshotStrategy ()
5266 snaphot_strategy .timeout .CopyFrom (snaphot_timeout_strategy )
@@ -62,18 +76,24 @@ def register(self, actors: List[ActorEntity]):
6276 registry .actors .get_or_create ("user_actor_01" ).CopyFrom (actor_01 )
6377
6478 actor_system = ActorSystem ()
65- actor_system .name = ' spawn-system'
79+ actor_system .name = " spawn-system"
6680 actor_system .registry .CopyFrom (registry )
6781
6882 service_info = ServiceInfo ()
69- service_info .service_name = 'spawn-python-sdk'
70- service_info .service_version = '0.1.0'
71- service_info .service_runtime = 'Python ' + platform .python_version () + \
72- ' [' + platform .python_implementation () + ' ' + \
73- platform .python_compiler () + ']'
74-
75- service_info .support_library_name = 'spawn-python-sdk'
76- service_info .support_library_version = '0.1.0'
83+ service_info .service_name = "spawn-python-sdk"
84+ service_info .service_version = "0.1.0"
85+ service_info .service_runtime = (
86+ "Python "
87+ + platform .python_version ()
88+ + " ["
89+ + platform .python_implementation ()
90+ + " "
91+ + platform .python_compiler ()
92+ + "]"
93+ )
94+
95+ service_info .support_library_name = "spawn-python-sdk"
96+ service_info .support_library_version = "0.1.0"
7797 service_info .protocol_major_version = 1
7898 service_info .protocol_minor_version = 1
7999
@@ -84,11 +104,10 @@ def register(self, actors: List[ActorEntity]):
84104 binary_payload = response .SerializeToString ()
85105
86106 resp = requests .post (
87- proxy_url ,
88- data = binary_payload ,
89- headers = self .default_headers
107+ proxy_url , data = binary_payload , headers = self .default_headers
90108 )
91109
92- logging .info (' Actors register response %s' , resp )
110+ logging .info (" Actors register response %s" , resp )
93111 except Exception as e :
112+ logging .error ("ERROR: %s" , e )
94113 logging .error ("Shit %s" , e .__cause__ )
0 commit comments