Skip to content

Commit e5212bb

Browse files
committed
Add register retries and backoff factor
1 parent dad28f0 commit e5212bb

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

spawn/eigr/functions/actors/internal/controller.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
Licensed under the Apache License, Version 2.0.
44
55
"""
6+
import logging
7+
import platform
8+
import requests
69

710
from spawn.eigr.functions.actors.api.actor import Actor as ActorEntity
811
from spawn.eigr.functions.actors.api.actor import ActorHandler
@@ -39,9 +42,7 @@
3942
from google.protobuf import symbol_database as _symbol_database
4043
from 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

4647
from typing import Any, MutableMapping
4748

@@ -52,13 +53,18 @@
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-
5759
TYPE_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

6067
def 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

7783
def 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

Comments
 (0)