Update app3.py
Browse files
app3.py
CHANGED
|
@@ -338,21 +338,55 @@ class TranslationOrchestrator:
|
|
| 338 |
self.notify_wordpress(notification_url, failure_data)
|
| 339 |
|
| 340 |
def notify_wordpress(self, notification_url: str, data: Dict):
|
|
|
|
| 341 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
response = requests.post(
|
| 343 |
notification_url,
|
| 344 |
json=data,
|
|
|
|
| 345 |
timeout=30,
|
| 346 |
-
verify=
|
| 347 |
)
|
| 348 |
|
|
|
|
|
|
|
| 349 |
if response.status_code == 200:
|
| 350 |
-
print(f"
|
|
|
|
| 351 |
else:
|
| 352 |
-
print(f"
|
|
|
|
|
|
|
| 353 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
except Exception as e:
|
| 355 |
-
print(f"
|
|
|
|
| 356 |
|
| 357 |
# Initialize FastAPI app
|
| 358 |
app = FastAPI(
|
|
|
|
| 338 |
self.notify_wordpress(notification_url, failure_data)
|
| 339 |
|
| 340 |
def notify_wordpress(self, notification_url: str, data: Dict):
|
| 341 |
+
"""Send notification to WordPress with improved error handling"""
|
| 342 |
try:
|
| 343 |
+
# Log the notification attempt
|
| 344 |
+
print(f"π€ Attempting to notify WordPress at: {notification_url}")
|
| 345 |
+
|
| 346 |
+
# Ensure HTTPS and proper URL format
|
| 347 |
+
if notification_url.startswith('http://localhost'):
|
| 348 |
+
# Replace localhost with the actual WordPress URL from environment
|
| 349 |
+
wordpress_url = os.getenv('WORDPRESS_BASE_URL', 'https://your-actual-site.com')
|
| 350 |
+
notification_url = notification_url.replace('http://localhost', wordpress_url)
|
| 351 |
+
|
| 352 |
+
# Ensure HTTPS
|
| 353 |
+
notification_url = notification_url.replace('http://', 'https://')
|
| 354 |
+
|
| 355 |
+
headers = {
|
| 356 |
+
'Content-Type': 'application/json',
|
| 357 |
+
'User-Agent': 'MLT-Orchestrator/1.0'
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
print(f"π Final notification URL: {notification_url}")
|
| 361 |
+
print(f"π¦ Payload keys: {list(data.keys())}")
|
| 362 |
+
|
| 363 |
response = requests.post(
|
| 364 |
notification_url,
|
| 365 |
json=data,
|
| 366 |
+
headers=headers,
|
| 367 |
timeout=30,
|
| 368 |
+
verify=True # Keep SSL verification enabled
|
| 369 |
)
|
| 370 |
|
| 371 |
+
print(f"π‘ WordPress notification response: {response.status_code}")
|
| 372 |
+
|
| 373 |
if response.status_code == 200:
|
| 374 |
+
print(f"β
WordPress notified successfully for {data['request_id']}")
|
| 375 |
+
return True
|
| 376 |
else:
|
| 377 |
+
print(f"β WordPress notification failed: HTTP {response.status_code}")
|
| 378 |
+
print(f"π Response: {response.text}")
|
| 379 |
+
return False
|
| 380 |
|
| 381 |
+
except requests.exceptions.Timeout:
|
| 382 |
+
print(f"β° WordPress notification timeout for {data['request_id']}")
|
| 383 |
+
return False
|
| 384 |
+
except requests.exceptions.ConnectionError as e:
|
| 385 |
+
print(f"π WordPress connection error for {data['request_id']}: {str(e)}")
|
| 386 |
+
return False
|
| 387 |
except Exception as e:
|
| 388 |
+
print(f"π₯ Notification error for {data['request_id']}: {str(e)}")
|
| 389 |
+
return False
|
| 390 |
|
| 391 |
# Initialize FastAPI app
|
| 392 |
app = FastAPI(
|