Spaces:
Running
Running
single tooltip component
Browse files- cronjob_service.py +5 -2
cronjob_service.py
CHANGED
|
@@ -57,6 +57,8 @@ def send_whatsapp_notification(message: str):
|
|
| 57 |
def call_service(url: str, token: str, service_name: str):
|
| 58 |
"""Modified: Existing logic with added notifications"""
|
| 59 |
start_time = datetime.now()
|
|
|
|
|
|
|
| 60 |
logger.info(f"Starting {service_name} at {start_time}")
|
| 61 |
|
| 62 |
try:
|
|
@@ -70,7 +72,8 @@ def call_service(url: str, token: str, service_name: str):
|
|
| 70 |
|
| 71 |
# New success notification
|
| 72 |
duration = (datetime.now() - start_time).total_seconds()
|
| 73 |
-
|
|
|
|
| 74 |
logger.info(success_msg)
|
| 75 |
send_whatsapp_notification(f"✅ {success_msg}")
|
| 76 |
|
|
@@ -80,7 +83,7 @@ def call_service(url: str, token: str, service_name: str):
|
|
| 80 |
logger.error(error_msg)
|
| 81 |
|
| 82 |
# New failure notification
|
| 83 |
-
send_whatsapp_notification(f"❌ {error_msg[:
|
| 84 |
raise # Maintains existing error propagation
|
| 85 |
|
| 86 |
def init_scheduler():
|
|
|
|
| 57 |
def call_service(url: str, token: str, service_name: str):
|
| 58 |
"""Modified: Existing logic with added notifications"""
|
| 59 |
start_time = datetime.now()
|
| 60 |
+
# Format for WhatsApp: "Mon 21 Apr 2024, 02:30 PM" (example)
|
| 61 |
+
formatted_time = start_time.strftime("%a %d %b %Y, %I:%M %p")
|
| 62 |
logger.info(f"Starting {service_name} at {start_time}")
|
| 63 |
|
| 64 |
try:
|
|
|
|
| 72 |
|
| 73 |
# New success notification
|
| 74 |
duration = (datetime.now() - start_time).total_seconds()
|
| 75 |
+
# Get day in DD-MM-YYYY format
|
| 76 |
+
success_msg = f"{service_name} succeeded in {duration:.2f}s (Status: {response.status_code}) on {formatted_time}"
|
| 77 |
logger.info(success_msg)
|
| 78 |
send_whatsapp_notification(f"✅ {success_msg}")
|
| 79 |
|
|
|
|
| 83 |
logger.error(error_msg)
|
| 84 |
|
| 85 |
# New failure notification
|
| 86 |
+
send_whatsapp_notification(f"❌ {error_msg[:10]} on {formatted_time}") # Truncate long errors
|
| 87 |
raise # Maintains existing error propagation
|
| 88 |
|
| 89 |
def init_scheduler():
|