返回所有调度决策轨迹记录(有限长度环形缓冲,最多 500 条)。 可选查询参数: - limit (int): 最多返回最近 N 条轨迹(默认返回全部) - outcome (str): 按结果过滤,可取 "scheduled"、"rejected"、"rerouted" 返回 JSON 结构: { "total": <缓冲中总条数>, "buffer_max": <缓冲上限>, "traces": [ { ...DecisionTrace 字段... }, ... ] }
()
| 1646 | |
| 1647 | @app.route('/api/decision_trace', methods=['GET']) |
| 1648 | def get_decision_traces(): |
| 1649 | """返回所有调度决策轨迹记录(有限长度环形缓冲,最多 500 条)。 |
| 1650 | |
| 1651 | 可选查询参数: |
| 1652 | - limit (int): 最多返回最近 N 条轨迹(默认返回全部) |
| 1653 | - outcome (str): 按结果过滤,可取 "scheduled"、"rejected"、"rerouted" |
| 1654 | |
| 1655 | 返回 JSON 结构: |
| 1656 | { |
| 1657 | "total": <缓冲中总条数>, |
| 1658 | "buffer_max": <缓冲上限>, |
| 1659 | "traces": [ { ...DecisionTrace 字段... }, ... ] |
| 1660 | } |
| 1661 | """ |
| 1662 | with simulation_engine.lock: |
| 1663 | buf = simulation_engine.decision_trace_buffer |
| 1664 | traces = buf.list_all() |
| 1665 | |
| 1666 | # 可选:按 outcome 过滤 |
| 1667 | outcome_filter = request.args.get("outcome") |
| 1668 | if outcome_filter: |
| 1669 | traces = [t for t in traces if t.outcome == outcome_filter] |
| 1670 | |
| 1671 | # 可选:限制返回条数(取最近 N 条) |
| 1672 | limit_str = request.args.get("limit") |
| 1673 | if limit_str is not None: |
| 1674 | try: |
| 1675 | limit = int(limit_str) |
| 1676 | if limit < 1: |
| 1677 | return error_response("INVALID_PARAM", "limit 必须为正整数"), 400 |
| 1678 | traces = traces[-limit:] |
| 1679 | except ValueError: |
| 1680 | return error_response("INVALID_PARAM", "limit 必须为整数"), 400 |
| 1681 | |
| 1682 | return jsonify(ok({ |
| 1683 | "total": len(simulation_engine.decision_trace_buffer), |
| 1684 | "buffer_max": simulation_engine.decision_trace_buffer.maxlen, |
| 1685 | "traces": [t.to_dict() for t in traces], |
| 1686 | })) |
| 1687 | |
| 1688 | |
| 1689 | @app.route('/api/decision_trace/<string:req_id>', methods=['GET']) |
nothing calls this directly
no test coverage detected