Peter Mutwiri commited on
Commit ·
53290a3
1
Parent(s): 30e8444
added kpi computations triger
Browse files
app/tasks/analytics_worker.py
CHANGED
|
@@ -396,11 +396,17 @@ async def redis_listener():
|
|
| 396 |
|
| 397 |
|
| 398 |
# ---- FastAPI Integration ---- #
|
| 399 |
-
|
| 400 |
-
"""
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 396 |
|
| 397 |
|
| 398 |
# ---- FastAPI Integration ---- #
|
| 399 |
+
async def trigger_kpi_computation(org_id: str, source_id: str):
|
| 400 |
+
"""Trigger the worker via Redis pubsub"""
|
| 401 |
+
try:
|
| 402 |
+
redis.publish(
|
| 403 |
+
f"analytics_trigger:{org_id}:{source_id}",
|
| 404 |
+
json.dumps({
|
| 405 |
+
"org_id": org_id,
|
| 406 |
+
"source_id": source_id,
|
| 407 |
+
"timestamp": datetime.now().isoformat()
|
| 408 |
+
})
|
| 409 |
+
)
|
| 410 |
+
logger.info(f"🎯 Triggered KPI computation: {org_id}/{source_id}")
|
| 411 |
+
except Exception as e:
|
| 412 |
+
logger.error(f"Trigger failed: {e}")
|