Skip to content

Commit bf2c30f

Browse files
authored
Merge pull request #3 from eigr-labs/dev/venkatesh
resolved issues with type hints
2 parents c14434d + 0b587c4 commit bf2c30f

File tree

2 files changed

+44
-25
lines changed

2 files changed

+44
-25
lines changed

example/joe.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ class JoeActor(ActorInit):
1313
# TODO: Remove this because it´s a bad design. Correct is extract this to superior Class
1414
def init() -> ActorParams:
1515
return ActorParams(
16-
name='joe',
16+
name="joe",
1717
state_type=JoeState,
1818
snapshot_timeout=10000,
19-
deactivate_timeout=120000
19+
deactivate_timeout=120000,
2020
)
2121

2222
entity = ActorEntity(init)
2323

2424
@entity.command("getActualState")
25-
def get_actual_state(self, ctx: ActorContext[JoeState]) -> Value:
25+
def get_actual_state(self, ctx: ActorContext) -> Value:
2626
current_state = ctx.state
2727
new_value = current_state
2828
return Value(current_state, new_value)
2929

3030
@entity.command("setLanguage")
31-
def set_language(self, req: Request, ctx: ActorContext[JoeState]) -> Value:
31+
def set_language(self, ctx: ActorContext) -> Value:
3232
reply = Reply()
3333
reply.response = "elf"
3434

spawn/controller.py

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@
22
Copyright 2022 Eigr.
33
Licensed 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

820
from spawn.entity import ActorEntity
921

@@ -16,25 +28,27 @@
1628

1729
class 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

Comments
 (0)