载入中...
搜索中...
未找到
QueueInspector.cpp
浏览该文件的文档.
2
5
6#include <cmath>
7
9namespace {
10bool matches(const std::string& actual, const std::string& filter) { return filter.empty() || actual == filter; }
11}
12
14 const std::string& state,
15 const std::string& kind) const {
16 QueueInspectionSnapshot result; result.domain = "orders";
17 for (int i = 0; i < queue.orderCount(); ++i) {
18 const auto borrowed = queue.orderAt(i); const auto* order = borrowed ? &borrowed->get() : nullptr;
19 if (!order) continue;
20 const std::string stateName = orders::stateName(order->state);
21 if (!matches(stateName, state) || !matches(order->kind, kind)) continue;
22 result.items.push_back({order->id, {}, order->kind, {}, stateName, order->priority,
23 order->elapsedSeconds, order->timeoutSeconds, order->payload.toJson()});
24 if (!std::isfinite(order->elapsedSeconds) || order->elapsedSeconds < 0.0 ||
25 !std::isfinite(order->timeoutSeconds) || order->timeoutSeconds < 0.0)
28 RuleId("editor.queue.invalid-order-time"), DiagnosticSeverity::Error,
29 "Order " + order->id + " has invalid timing metadata"));
30 if (order->timeoutSeconds > 0.0 && order->elapsedSeconds > order->timeoutSeconds &&
33 eve::DiagnosticCode::PreconditionViolation, RuleId("editor.queue.overdue-order"),
34 DiagnosticSeverity::Warning,
35 "Order " + order->id + " exceeded its timeout without failing"));
36 }
37 for (int i = 0; i < queue.eventCount(); ++i) {
38 const auto borrowed = queue.eventAt(i);
39 const auto* event = borrowed ? &borrowed->get() : nullptr;
40 if (!event) continue;
41 result.events.push_back({event->sequence, 0, event->orderId, event->kind,
42 orders::stateName(event->from), orders::stateName(event->to), event->reason});
43 }
44 return result;
45}
46
48 const std::string& owner,
49 const std::string& state,
50 const std::string& kind) const {
51 QueueInspectionSnapshot result; result.domain = "production";
52 for (int i = 0; i < queue.taskCount(); ++i) {
53 const auto borrowed = queue.taskAt(i); const auto* task = borrowed ? &borrowed->get() : nullptr;
54 if (!task) continue;
55 const std::string stateName(production::taskStateName(task->state));
56 if (!matches(task->owner, owner) || !matches(stateName, state) || !matches(task->kind, kind)) continue;
57 const double progress = task->progress.seconds(); const double duration = task->duration.seconds();
58 result.items.push_back({task->id, task->owner, task->kind, task->product, stateName,
59 task->priority, progress, duration, {}});
60 if (!std::isfinite(progress) || !std::isfinite(duration) || progress < 0.0 || duration <= 0.0 ||
61 progress > duration)
64 RuleId("editor.queue.invalid-production-progress"), DiagnosticSeverity::Error,
65 "Production task " + task->id + " has invalid progress"));
66 }
67 for (int i = 0; i < queue.eventCount(); ++i) {
68 const auto borrowed = queue.eventAt(i); const auto* event = borrowed ? &borrowed->get() : nullptr;
69 if (!event) continue;
70 result.events.push_back({event->sequence, event->tick.value(), event->taskId,
71 std::string(production::eventKindName(event->kind)), {}, {}, event->reason});
72 }
73 return result;
74}
75
76} // namespace eve::queue_editing
float duration
TokenKind kind
std::vector< std::int32_t > order
const RuntimeTensor * borrowed
std::string filter
Generic priority order queue with no gameplay or entity semantics.
eve::OptionalRef< OrderEvent > eventAt(int index)
Returns an event by sequence order, or null for an invalid index.
int orderCount() const
Returns the total retained order count.
eve::OptionalRef< Order > orderAt(int index)
Returns an order in creation order, or null for an invalid index.
int eventCount() const
Returns the number of retained deterministic events.
Generic multi-owner, multi-slot continuous-progress work queue.
Definition Production.h:200
int taskCount() const
Returns retained task count in enqueue order.
int eventCount() const
Returns retained event count.
eve::OptionalRef< const ProductionTask > taskAt(int index)
Returns a retained task by enqueue index, or an empty borrowed reference.
eve::OptionalRef< ProductionEvent > eventAt(int index)
Returns an event by sequence index, or an empty borrowed reference.
QueueInspectionSnapshot capture(const orders::CommandQueue &queue, const std::string &state={}, const std::string &kind={}) const
Capture an Orders queue and optionally filter by state or kind.
Diagnostic ruleDiagnostic(eve::DiagnosticCode code, RuleId rule, DiagnosticSeverity severity, std::string message)
Build a common diagnostic carrying an open editing rule identity.
std::string stateName(OrderState state)
Returns the stable lowercase name of a state.
std::string_view eventKindName(ProductionEventKind kind)
Returns the stable lowercase name of an event kind.
std::string_view taskStateName(TaskState state)
Returns the stable lowercase name of a task state.
editing::RuleId RuleId
Immutable queue inspection result with structured diagnostics.
std::vector< QueueEventSnapshot > events
std::vector< EditorDiagnostic > diagnostics
std::vector< QueueItemSnapshot > items