33Licensed under the Apache License, Version 2.0.
44
55"""
6+ import logging
7+ import platform
8+ import requests
69
710from spawn .eigr .functions .actors .api .actor import Actor as ActorEntity
811from spawn .eigr .functions .actors .api .actor import ActorHandler
3942from google .protobuf import symbol_database as _symbol_database
4043from google .protobuf .any_pb2 import Any as AnyProto
4144
42- import logging
43- import platform
44- import requests
45+ from requests .adapters import HTTPAdapter , Retry
4546
4647from typing import Any , MutableMapping
4748
5253 "Content-Type" : "application/octet-stream" ,
5354}
5455
56+ _DEFAULT_MAX_RETRIES = 100
57+ _DEFAULT_MAX_RETRIES_BACKOFF_FACTOR = 0.2
5558_REGISTER_URI = "/api/v1/system"
56-
5759TYPE_URL_PREFIX = 'type.googleapis.com/'
5860
61+ req = requests .Session ()
62+ retries = Retry (total = _DEFAULT_MAX_RETRIES ,
63+ backoff_factor = _DEFAULT_MAX_RETRIES_BACKOFF_FACTOR )
64+ req .mount ('http://' , HTTPAdapter (max_retries = retries ))
65+
5966
6067def get_payload (input ):
61- print (input )
6268 input_type : str = input .type_url
6369 if input_type .startswith (TYPE_URL_PREFIX ):
6470 input_type = input_type [len (TYPE_URL_PREFIX ):]
@@ -75,7 +81,6 @@ def pack(input):
7581
7682
7783def handle_response (system , actor_name , result ):
78- print ("Result ----- {}" .format (result ))
7984 actor_invocation_response = ActorInvocationResponse ()
8085 actor_invocation_response .actor_name = actor_name
8186 actor_invocation_response .actor_system = system
@@ -122,6 +127,7 @@ def handle_invoke(self, data) -> ActorInvocationResponse:
122127 actor_invocation = ActorInvocation ()
123128 actor_invocation .ParseFromString (databytes )
124129 logging .debug ('Actor invocation data: %s' , actor_invocation )
130+
125131 actor_id = actor_invocation .actor
126132 actor_system = actor_id .system
127133 actor_name = actor_id .name
@@ -200,14 +206,15 @@ def register(self):
200206 deactivate_strategy )
201207
202208 # Set metadata
203- actor_metatdata = Metadata ()
209+ actor_metadata = Metadata ()
204210
205- if ( entity . settings . channel is not None and len ( entity .settings .channel ) > 0 ):
206- actor_metatdata . channel_group = entity . settings . channel
211+ for key , value in entity .settings .tags . items ( ):
212+ actor_metadata . tags [ key ] = value
207213
208- # actor_metatdata.tags["actor"] = "user_actor_template"
214+ if (entity .settings .channel is not None and len (entity .settings .channel ) > 0 ):
215+ actor_metadata .channel_group = entity .settings .channel
209216
210- actor_template .metadata .CopyFrom (actor_metatdata )
217+ actor_template .metadata .CopyFrom (actor_metadata )
211218
212219 # Set settings
213220 if entity .settings .kind == ActorKind .NAMED :
@@ -266,7 +273,7 @@ def register(self):
266273
267274 binary_payload = request .SerializeToString ()
268275
269- resp = requests .post (
276+ resp = req .post (
270277 proxy_url , data = binary_payload , headers = _DEFAULT_HEADERS
271278 )
272279
0 commit comments