rb-commons 0.2.4__py3-none-any.whl → 0.2.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -73,6 +73,8 @@ class BaseAPI:
73
73
 
74
74
  except RequestException as e:
75
75
  raise BadRequestException(f"Request failed: {e}")
76
+ except BadRequestException as e:
77
+ raise BadRequestException(e.message)
76
78
  except (json.JSONDecodeError, ValueError) as e:
77
79
  raise InternalException(f"Failed to parse JSON: {e}")
78
80
  except Exception as e:
rb_commons/http/consul.py CHANGED
@@ -9,7 +9,7 @@ class ServiceDiscovery:
9
9
  self.consul_client = consul.Consul(host=configs.consul_host, port=configs.consul_port)
10
10
  self.cache = aiocache.Cache(aiocache.SimpleMemoryCache)
11
11
 
12
- async def get_service_instances(self, service_name: str) -> dict:
12
+ async def _get_service_instances(self, service_name: str) -> dict:
13
13
  """Get a healthy service instance from Consul"""
14
14
  index, services = self.consul_client.health.service(service_name, passing=True)
15
15
 
@@ -18,12 +18,12 @@ class ServiceDiscovery:
18
18
  detail="Service not available")
19
19
  return services
20
20
 
21
- def select_instance(self, instances: list, request: Request) -> dict:
21
+ def _select_instance(self, instances: list, host: str) -> dict:
22
22
  """Select instance using consistent hashing"""
23
23
  if not instances:
24
24
  raise HTTPException(status_code=503, detail="No healthy instances")
25
25
 
26
- key = request.client.host
26
+ key = host
27
27
  hash_value = hash(key)
28
28
  return instances[hash_value % len(instances)]
29
29
 
@@ -32,15 +32,13 @@ class ServiceDiscovery:
32
32
  cache_key = f"service:{service_name}"
33
33
  instances = await self.cache.get(cache_key)
34
34
  if not instances:
35
- instances = await self.get_service_instances(service_name)
35
+ instances = await self._get_service_instances(service_name)
36
36
  if instances:
37
37
  await self.cache.set(cache_key, instances, ttl=30) # Cache for 30 seconds
38
38
  return instances
39
39
 
40
- def build_target_url(self, instance: dict, path: str,
41
- request: Request) -> str:
40
+ def _build_instance_url(self, instance: dict) -> str:
42
41
  """Build target URL with proper path handling"""
43
42
  service_address = instance['Service']['Address'] or instance['Node']['Address']
44
43
  service_port = instance['Service']['Port']
45
- target_path = request.url.path.replace(path, "", 1)
46
- return f"http://{service_address}:{service_port}{path}{target_path}"
44
+ return f"http://{service_address}:{service_port}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rb-commons
3
- Version: 0.2.4
3
+ Version: 0.2.6
4
4
  Summary: Commons of project and simplified orm based on sqlalchemy.
5
5
  Home-page: https://github.com/RoboSell-organization/rb-commons
6
6
  Author: Abdulvoris
@@ -6,8 +6,8 @@ rb_commons/configs/config.py,sha256=zla62zy3UfjE2YpvSDwsfhP2Qsm0BbGsycngfyiVvE4,
6
6
  rb_commons/configs/injections.py,sha256=6B1EOgIGnkWv3UrFaV9PRgG0-CJAbLu1UZ3kq-SjPVU,273
7
7
  rb_commons/configs/rabbitmq.py,sha256=vUqa_PcZkPp1lX0B6HLSAXVMUcPR2_8-8cN-C7xFxRI,741
8
8
  rb_commons/http/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- rb_commons/http/base_api.py,sha256=W-nXoO0TcngSMVgmJHFRdXeOrI9FDPi36I_Ih8hP3VE,4824
10
- rb_commons/http/consul.py,sha256=fFqvMueo_-AWxOE4NEsikC4tvHbS6QD8l5JnoW8jyIQ,2026
9
+ rb_commons/http/base_api.py,sha256=H0y5eClRzDMPeltSYeUd0xNCl6iqTD-7cW809Juv9_I,4916
10
+ rb_commons/http/consul.py,sha256=mjMjLH7l7ub6A-_84impzDTwLjTXlwMG_VRlaNSFslc,1872
11
11
  rb_commons/http/exceptions.py,sha256=EGRMr1cRgiJ9Q2tkfANbf0c6-zzXf1CD6J3cmCaT_FA,1885
12
12
  rb_commons/orm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  rb_commons/orm/exceptions.py,sha256=1aMctiEwrPjyehoXVX1l6ML5ZOhmDkmBISzlTD5ey1Y,509
@@ -18,7 +18,7 @@ rb_commons/schemes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
18
18
  rb_commons/schemes/jwt.py,sha256=F66JJDhholuOPPzlKeoC6f1TL4gXg4oRUrV5yheNpyo,1675
19
19
  rb_commons/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
20
  rb_commons/utils/media.py,sha256=KNY_9SdRa3Rp7d3B1tZaXkhmzVa65RcS62BYwZP1bVM,332
21
- rb_commons-0.2.4.dist-info/METADATA,sha256=I_QUMkGmUek2TX9zJIDw_U5Ws0lV5JhrwXS22Tw-t_g,6570
22
- rb_commons-0.2.4.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
23
- rb_commons-0.2.4.dist-info/top_level.txt,sha256=HPx_WAYo3_fbg1WCeGHsz3wPGio1ucbnrlm2lmqlJog,11
24
- rb_commons-0.2.4.dist-info/RECORD,,
21
+ rb_commons-0.2.6.dist-info/METADATA,sha256=o0oX_BS0KiCefgYhAnz-CtK8O0vLO06NNvSAL7wpxsw,6570
22
+ rb_commons-0.2.6.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
23
+ rb_commons-0.2.6.dist-info/top_level.txt,sha256=HPx_WAYo3_fbg1WCeGHsz3wPGio1ucbnrlm2lmqlJog,11
24
+ rb_commons-0.2.6.dist-info/RECORD,,