microservice-chassis-grupo2-cc-prod 0.1.6__py3-none-any.whl → 0.1.9__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.
- microservice_chassis_grupo2/core/consul.py +17 -8
- {microservice_chassis_grupo2_cc_prod-0.1.6.dist-info → microservice_chassis_grupo2_cc_prod-0.1.9.dist-info}/METADATA +1 -1
- {microservice_chassis_grupo2_cc_prod-0.1.6.dist-info → microservice_chassis_grupo2_cc_prod-0.1.9.dist-info}/RECORD +5 -5
- {microservice_chassis_grupo2_cc_prod-0.1.6.dist-info → microservice_chassis_grupo2_cc_prod-0.1.9.dist-info}/WHEEL +0 -0
- {microservice_chassis_grupo2_cc_prod-0.1.6.dist-info → microservice_chassis_grupo2_cc_prod-0.1.9.dist-info}/top_level.txt +0 -0
|
@@ -30,11 +30,10 @@ class ConsulClient:
|
|
|
30
30
|
service_name: str
|
|
31
31
|
) -> dict:
|
|
32
32
|
try:
|
|
33
|
-
async with httpx.AsyncClient() as client:
|
|
33
|
+
async with httpx.AsyncClient(verify=False) as client:
|
|
34
34
|
response = await client.get(
|
|
35
35
|
f"{self.base_url}/catalog/service/{service_name}",
|
|
36
36
|
timeout=10.0,
|
|
37
|
-
verify=False
|
|
38
37
|
)
|
|
39
38
|
if response.status_code == 200:
|
|
40
39
|
services = response.json()
|
|
@@ -44,7 +43,12 @@ class ConsulClient:
|
|
|
44
43
|
"address": service.get("ServiceAddress") or service.get("Address"),
|
|
45
44
|
"port": service.get("ServicePort"),
|
|
46
45
|
}
|
|
46
|
+
else:
|
|
47
|
+
with open("/home/pyuser/code/log_consul.txt", "a") as f:
|
|
48
|
+
f.write(f"Consul response code: {response.status_code}\n")
|
|
47
49
|
except Exception as e:
|
|
50
|
+
with open("/home/pyuser/code/log_consul.txt", "a") as f:
|
|
51
|
+
f.write(f"Consul error: {type(e).__name__}: {str(e)}\n")
|
|
48
52
|
return None
|
|
49
53
|
|
|
50
54
|
_consul_client = None
|
|
@@ -58,24 +62,29 @@ def create_consul_client() -> ConsulClient:
|
|
|
58
62
|
return _consul_client
|
|
59
63
|
|
|
60
64
|
async def get_service_url(service_name: str, default_url: str = None) -> str:
|
|
61
|
-
"""Get service URL from Consul with retry and fallback."""
|
|
62
65
|
consul_client = create_consul_client()
|
|
63
66
|
max_retries = 5
|
|
64
67
|
retry_delay = 1
|
|
68
|
+
last_error: Exception | None = None
|
|
65
69
|
|
|
66
70
|
for attempt in range(max_retries):
|
|
67
71
|
try:
|
|
68
72
|
service_info = await consul_client.discover_service(service_name)
|
|
69
73
|
if service_info:
|
|
70
|
-
|
|
71
|
-
return url
|
|
74
|
+
return f"https://{service_info['address']}:{service_info['port']}"
|
|
72
75
|
except Exception as e:
|
|
73
|
-
|
|
76
|
+
last_error = e
|
|
77
|
+
|
|
74
78
|
if attempt < max_retries - 1:
|
|
75
79
|
await asyncio.sleep(retry_delay)
|
|
76
80
|
|
|
77
|
-
# Fallback to default
|
|
78
81
|
if default_url:
|
|
79
82
|
return default_url
|
|
80
83
|
|
|
81
|
-
|
|
84
|
+
if last_error:
|
|
85
|
+
raise RuntimeError(
|
|
86
|
+
f"Could not discover service '{service_name}': "
|
|
87
|
+
f"{last_error.__class__.__name__}: {last_error}"
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
raise RuntimeError(f"Could not discover service '{service_name}': no instances found")
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
microservice_chassis_grupo2/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
microservice_chassis_grupo2/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
microservice_chassis_grupo2/core/config.py,sha256=fCXb0ZdlKqYKGlFecEDyHVq__EqptuHnUcNj_iiJITo,2167
|
|
4
|
-
microservice_chassis_grupo2/core/consul.py,sha256=
|
|
4
|
+
microservice_chassis_grupo2/core/consul.py,sha256=Pw7acb5XeBpWvnMhQKGTlZui1Q2Sy1L9Djxb4L59CFU,3051
|
|
5
5
|
microservice_chassis_grupo2/core/dependencies.py,sha256=l2g1p5b9b104SOHVCe6WJcz5_c6vyU6OdDewAmxOyiQ,1988
|
|
6
6
|
microservice_chassis_grupo2/core/rabbitmq_core.py,sha256=-PEqhaPZnUl6B1jDQ3Or5kMlb47MijEm7DOHopKoO4o,6124
|
|
7
7
|
microservice_chassis_grupo2/core/router_utils.py,sha256=BczZZO9LDWWTWNxCDYYJXHe-E1Cqew7TbLzr5hKnxQc,766
|
|
@@ -10,7 +10,7 @@ microservice_chassis_grupo2/core/security.py,sha256=e4uGs299JW8hdPFi3hqdRB7TRylQ
|
|
|
10
10
|
microservice_chassis_grupo2/sql/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
11
|
microservice_chassis_grupo2/sql/database.py,sha256=EHRdFFbHUQx2Kmnu1Y8Gkipu_dd8W52fF7nDMV5oIrk,4157
|
|
12
12
|
microservice_chassis_grupo2/sql/models.py,sha256=jhRS2NBhVpwJGHt620N3gcgdszngzzqS3R_I3NOKK8o,1289
|
|
13
|
-
microservice_chassis_grupo2_cc_prod-0.1.
|
|
14
|
-
microservice_chassis_grupo2_cc_prod-0.1.
|
|
15
|
-
microservice_chassis_grupo2_cc_prod-0.1.
|
|
16
|
-
microservice_chassis_grupo2_cc_prod-0.1.
|
|
13
|
+
microservice_chassis_grupo2_cc_prod-0.1.9.dist-info/METADATA,sha256=LMPt8TOZ9VuIRfd0pHhwiTDqVxsJVCkxm7cPTjGW3o0,3230
|
|
14
|
+
microservice_chassis_grupo2_cc_prod-0.1.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
15
|
+
microservice_chassis_grupo2_cc_prod-0.1.9.dist-info/top_level.txt,sha256=gAbQlQALJPI7wCWahNa12XvGlherC3Jf9C2X4Y80DXU,28
|
|
16
|
+
microservice_chassis_grupo2_cc_prod-0.1.9.dist-info/RECORD,,
|
|
File without changes
|