diff --git a/example/joe.py b/example/joe.py index 3f103aa..f92ff1d 100644 --- a/example/joe.py +++ b/example/joe.py @@ -13,22 +13,22 @@ class JoeActor(ActorInit): # TODO: Remove this because it´s a bad design. Correct is extract this to superior Class def init() -> ActorParams: return ActorParams( - name='joe', + name="joe", state_type=JoeState, snapshot_timeout=10000, - deactivate_timeout=120000 + deactivate_timeout=120000, ) entity = ActorEntity(init) @entity.command("getActualState") - def get_actual_state(self, ctx: ActorContext[JoeState]) -> Value: + def get_actual_state(self, ctx: ActorContext) -> Value: current_state = ctx.state new_value = current_state return Value(current_state, new_value) @entity.command("setLanguage") - def set_language(self, req: Request, ctx: ActorContext[JoeState]) -> Value: + def set_language(self, ctx: ActorContext) -> Value: reply = Reply() reply.response = "elf" diff --git a/spawn/controller.py b/spawn/controller.py index 4f8dcd9..0674acb 100644 --- a/spawn/controller.py +++ b/spawn/controller.py @@ -2,8 +2,20 @@ Copyright 2022 Eigr. Licensed under the Apache License, Version 2.0. """ -from spawn.eigr.actor_pb2 import Actor, ActorDeactivateStrategy, ActorSnapshotStrategy, ActorState, ActorSystem, Registry, TimeoutStrategy -from spawn.eigr.protocol_pb2 import RegistrationRequest, RegistrationResponse, ServiceInfo +from spawn.eigr.actor_pb2 import ( + Actor, + ActorDeactivateStrategy, + ActorSnapshotStrategy, + ActorState, + ActorSystem, + Registry, + TimeoutStrategy, +) +from spawn.eigr.protocol_pb2 import ( + RegistrationRequest, + RegistrationResponse, + ServiceInfo, +) from spawn.entity import ActorEntity @@ -16,25 +28,27 @@ class SpawnActorController: - register_uri = '/api/v1/system' + register_uri = "/api/v1/system" default_headers = { "Accept": "application/octet-stream", - "Content-Type": "application/octet-stream" + "Content-Type": "application/octet-stream", } def __init__(self, host: str, port: str): self.host = host self.port = port - def invoke(self, actor_name: str, actor_command: str, arg: Any, output_type: Any) -> Any: + def invoke( + self, actor_name: str, actor_command: str, arg: Any, output_type: Any + ) -> Any: return "" def register(self, actors: List[ActorEntity]): - logging.info('Registering Actors on the Proxy %s', actors) + logging.info("Registering Actors on the Proxy %s", actors) try: - proxy_url = 'http://{}:{}{}'.format(self.host, self.port, self.register_uri) + proxy_url = "http://{}:{}{}".format(self.host, self.port, self.register_uri) # Create actor params via ActorEntity deactivate_timeout_strategy = TimeoutStrategy() @@ -46,7 +60,7 @@ def register(self, actors: List[ActorEntity]): actor_state = ActorState() deactivate_strategy = ActorDeactivateStrategy() - deactivate_strategy.timeout.CopyFrom(deactivate_timeout_strategy) + deactivate_strategy.timeout.CopyFrom(deactivate_timeout_strategy) snaphot_strategy = ActorSnapshotStrategy() snaphot_strategy.timeout.CopyFrom(snaphot_timeout_strategy) @@ -62,18 +76,24 @@ def register(self, actors: List[ActorEntity]): registry.actors.get_or_create("user_actor_01").CopyFrom(actor_01) actor_system = ActorSystem() - actor_system.name = 'spawn-system' + actor_system.name = "spawn-system" actor_system.registry.CopyFrom(registry) service_info = ServiceInfo() - service_info.service_name = 'spawn-python-sdk' - service_info.service_version = '0.1.0' - service_info.service_runtime = 'Python ' + platform.python_version() + \ - ' [' + platform.python_implementation() + ' ' + \ - platform.python_compiler() + ']' - - service_info.support_library_name = 'spawn-python-sdk' - service_info.support_library_version = '0.1.0' + service_info.service_name = "spawn-python-sdk" + service_info.service_version = "0.1.0" + service_info.service_runtime = ( + "Python " + + platform.python_version() + + " [" + + platform.python_implementation() + + " " + + platform.python_compiler() + + "]" + ) + + service_info.support_library_name = "spawn-python-sdk" + service_info.support_library_version = "0.1.0" service_info.protocol_major_version = 1 service_info.protocol_minor_version = 1 @@ -84,11 +104,10 @@ def register(self, actors: List[ActorEntity]): binary_payload = response.SerializeToString() resp = requests.post( - proxy_url, - data=binary_payload, - headers=self.default_headers + proxy_url, data=binary_payload, headers=self.default_headers ) - logging.info('Actors register response %s', resp) + logging.info("Actors register response %s", resp) except Exception as e: + logging.error("ERROR: %s", e) logging.error("Shit %s", e.__cause__)