Spaces:
Sleeping
Sleeping
Refactor emit_metric to use structured payload dict
Browse filesPass a single dict payload instead of positional args to avoid
arg-order bugs and ensure temporal fields (fiscal_year, end_date,
form) are not dropped. Adds debug logging of the JSON payload.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- app.py +10 -3
- mcp_client.py +11 -4
app.py
CHANGED
|
@@ -238,11 +238,18 @@ async def handle_message_send(params: dict, request_id: Any) -> dict:
|
|
| 238 |
|
| 239 |
|
| 240 |
def create_progress_callback(task_id: str):
|
| 241 |
-
"""Create a progress callback that
|
| 242 |
-
def callback(
|
| 243 |
-
end_date: str = None, fiscal_year: int = None, form: str = None):
|
| 244 |
task = TASK_STORE.get(task_id)
|
| 245 |
if task and task.status == TaskStatus.WORKING:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
entry = MetricEntry(
|
| 247 |
source=source,
|
| 248 |
metric=metric,
|
|
|
|
| 238 |
|
| 239 |
|
| 240 |
def create_progress_callback(task_id: str):
|
| 241 |
+
"""Create a progress callback that receives structured metric payloads."""
|
| 242 |
+
def callback(payload: dict):
|
|
|
|
| 243 |
task = TASK_STORE.get(task_id)
|
| 244 |
if task and task.status == TaskStatus.WORKING:
|
| 245 |
+
# Extract fields from structured payload
|
| 246 |
+
source = payload.get("source", "unknown")
|
| 247 |
+
metric = payload.get("metric", "unknown")
|
| 248 |
+
value = payload.get("value")
|
| 249 |
+
end_date = payload.get("end_date")
|
| 250 |
+
fiscal_year = payload.get("fiscal_year")
|
| 251 |
+
form = payload.get("form")
|
| 252 |
+
|
| 253 |
entry = MetricEntry(
|
| 254 |
source=source,
|
| 255 |
metric=metric,
|
mcp_client.py
CHANGED
|
@@ -35,11 +35,18 @@ async def emit_metric(
|
|
| 35 |
fiscal_year: int = None,
|
| 36 |
form: str = None
|
| 37 |
):
|
| 38 |
-
"""Emit a metric event with optional temporal data
|
| 39 |
if progress_callback:
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
await asyncio.sleep(METRIC_DELAY_MS / 1000)
|
| 44 |
|
| 45 |
|
|
|
|
| 35 |
fiscal_year: int = None,
|
| 36 |
form: str = None
|
| 37 |
):
|
| 38 |
+
"""Emit a metric event as a structured payload with optional temporal data."""
|
| 39 |
if progress_callback:
|
| 40 |
+
payload = {
|
| 41 |
+
"source": source,
|
| 42 |
+
"metric": metric,
|
| 43 |
+
"value": value,
|
| 44 |
+
"end_date": end_date,
|
| 45 |
+
"fiscal_year": fiscal_year,
|
| 46 |
+
"form": form,
|
| 47 |
+
}
|
| 48 |
+
logger.debug(f"emit_metric payload: {json.dumps(payload, default=str)}")
|
| 49 |
+
progress_callback(payload)
|
| 50 |
await asyncio.sleep(METRIC_DELAY_MS / 1000)
|
| 51 |
|
| 52 |
|