载入中...
搜索中...
未找到
Production.cpp
浏览该文件的文档.
18eve::Result<T> productionBindingFailure(eve::DiagnosticCode code, std::string message, std::string path = {}) {
24 return state == TaskState::Completed || state == TaskState::Cancelled || state == TaskState::Failed;
32eve::Result<ScaledWork> scaleWork(std::int64_t effortNanoseconds, std::uint32_t efficiencyPermille,
42 const auto tailNumerator = tail * static_cast<std::int64_t>(efficiencyPermille) + remainderPermille;
85void WorkQueue::emit(ProductionEventKind kind, const ProductionTask& task, std::string_view reason) {
87 {{nextEventSequence_++, std::string(reason)}, tick_, kind, task.id, task.owner, task.kind, task.product,
120 if (used + requirement.units > resourceCapacity(task.owner, requirement.resource)) return false;
165 if (task.repeat.maintainStockTarget >= 0 && task.repeat.observedStock >= task.repeat.maintainStockTarget)
167 if (!resourcesAvailable(task)) return eve::Result<std::string>::success("resource_unavailable");
216eve::Result<std::string> WorkQueue::enqueue(std::string_view owner, std::string_view kind, std::string_view product,
261 const auto validateDependencies = [this, &dependencyIds](const std::vector<std::string>& values,
274 auto prerequisites = validateDependencies(request.dependencies.prerequisites, "dependencies.prerequisites");
313 task->correlationId = request.correlationId.empty() ? task->id : std::move(request.correlationId);
328 std::find_if(tasks_.begin(), tasks_.end(), [&taskId](const auto& task) { return task->id == taskId; });
340 std::find_if(tasks_.begin(), tasks_.end(), [&taskId](const auto& task) { return task->id == taskId; });
348 return productionBindingFailure<void>(eve::DiagnosticCode::NotFound, "work task was not found", "taskId");
361 return productionBindingFailure<void>(eve::DiagnosticCode::NotFound, "work task was not found", "taskId");
363 return productionBindingFailure<void>(eve::DiagnosticCode::Conflict, "only paused tasks can be resumed",
374 return productionBindingFailure<void>(eve::DiagnosticCode::NotFound, "work task was not found", "taskId");
376 return productionBindingFailure<void>(eve::DiagnosticCode::Conflict, "terminal work tasks cannot be cancelled",
389 return productionBindingFailure<void>(eve::DiagnosticCode::NotFound, "work task was not found", "taskId");
391 return productionBindingFailure<void>(eve::DiagnosticCode::Conflict, "terminal work tasks cannot fail",
401eve::Result<void> WorkQueue::settle(std::string_view taskId, ProductionSettlementReceipt receipt) {
404 return productionBindingFailure<void>(eve::DiagnosticCode::NotFound, "work task was not found", "taskId");
405 if ((!task->settlement.settlementId.empty() && task->settlement.settlementId == receipt.settlementId) ||
409 return productionBindingFailure<void>(eve::DiagnosticCode::Conflict, "work task is not ready to settle", "taskId");
427 return productionBindingFailure<void>(eve::DiagnosticCode::NotFound, "work task was not found", "taskId");
429 return productionBindingFailure<void>(eve::DiagnosticCode::Conflict, "work task is not ready to settle", "taskId");
431 return productionBindingFailure<void>(eve::DiagnosticCode::InvalidArgument, "settlement failure needs a reason");
441 return productionBindingFailure<void>(eve::DiagnosticCode::NotFound, "work task was not found", "taskId");
443 return productionBindingFailure<void>(eve::DiagnosticCode::Conflict, "work task has no failed settlement", "taskId");
486eve::Result<void> WorkQueue::contribute(std::string_view taskId, WorkContribution contribution) {
489 return productionBindingFailure<void>(eve::DiagnosticCode::NotFound, "work task was not found", "taskId");
563eve::Result<void> WorkQueue::setResourceCapacity(std::string_view owner, std::string_view resource, int capacity) {
592 std::count_if(tasks_.begin(), tasks_.end(), [&owner](const auto& t) { return t->owner == owner; }));
595eve::OptionalRef<const ProductionTask> WorkQueue::ownerTaskAt(std::string_view owner, int index) {
602eve::OptionalRef<const ProductionTask> WorkQueue::ownerTaskAt(std::string_view owner, int index) const {
std::vector< ecs::EntityHandle > schedule
The round's activation queue, resolved against the target battle.
Definition TacticsPersistence.cpp:170
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
constexpr std::int64_t nanoseconds() const noexcept
Return the exact signed nanosecond representation.
Definition Time.h:69
static Result< Duration > fromSeconds(double seconds)
Convert finite seconds to the nearest nanosecond.
Definition Time.cpp:16
static constexpr Duration fromNanoseconds(std::int64_t nanoseconds) noexcept
Construct an exact duration from nanoseconds.
Definition Time.h:55
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.h:81
const T * getIf() const noexcept
Return a typed pointer, or nullptr when the kind differs.
Definition Value.h:180
constexpr std::optional< StrongUint64 > incremented() const noexcept
Returns the next value, or empty instead of unsigned wraparound.
Definition StrongUint64.h:30
eve::Result< void > settle(std::string_view taskId, ProductionSettlementReceipt receipt)
Atomically marks a ready task settled and retains its idempotency receipt.
Definition Production.cpp:401
eve::Result< std::string > blockReason(std::string_view taskId) const
Returns the deterministic reason a task cannot start, or an empty string when runnable.
Definition Production.cpp:125
bool definitionAvailable(std::string_view owner, const eve::definition::DefinitionHandle &definition) const
Reports whether an exact definition incarnation is available to an owner.
Definition ProductionAdvanced.cpp:40
bool tagAvailable(std::string_view owner, std::string_view tag) const
Reports whether an exact tag is available to an owner.
Definition ProductionAdvanced.cpp:46
eve::OptionalRef< const ProductionTask > find(std::string_view taskId)
Finds a retained task by stable ID.
Definition Production.cpp:332
eve::Result< void > contribute(std::string_view taskId, WorkContribution contribution)
Applies deterministic external work after efficiency scaling.
Definition Production.cpp:486
eve::Result< void > failSettlement(std::string_view taskId, std::string_view reason)
Records a retryable domain settlement failure without losing completed work.
Definition Production.cpp:424
eve::OptionalRef< const ProductionTask > ownerTaskAt(std::string_view owner, int index)
Returns an owner's retained task by enqueue index, or an empty borrowed reference.
Definition Production.cpp:595
SchedulerStrategy schedulerStrategy(std::string_view owner) const
Returns an owner's queue ordering strategy, defaulting to Priority.
Definition ProductionAdvanced.cpp:34
eve::Result< void > resume(std::string_view taskId)
Returns a paused task to deterministic scheduling.
Definition Production.cpp:358
eve::Result< void > cancel(std::string_view taskId, std::string_view reason="cancelled")
Cancels a non-terminal task with a structured outcome.
Definition Production.cpp:371
eve::Result< void > setSlotCount(std::string_view owner, int slots)
Sets an owner's parallel slot count; zero prevents new tasks from running.
Definition Production.cpp:549
eve::Result< void > retrySettlement(std::string_view taskId)
Returns a failed settlement to the ready state for an explicit retry.
Definition Production.cpp:438
int resourceCapacity(std::string_view owner, std::string_view resource) const
Returns named capacity, defaulting slot to slotCount and other resources to zero.
Definition Production.cpp:104
eve::OptionalRef< const ProductionTask > taskAt(int index)
Returns a retained task by enqueue index, or an empty borrowed reference.
Definition Production.cpp:580
eve::Result< void > setResourceCapacity(std::string_view owner, std::string_view resource, int capacity)
Sets named running capacity for an owner; zero disables that capability.
Definition Production.cpp:563
int runningCount(std::string_view owner) const
Returns the number of currently running tasks for an owner.
Definition Production.cpp:98
eve::Result< void > advance(const eve::SimulationStep &step)
Applies one injected deterministic simulation step.
Definition Production.cpp:509
eve::Result< std::string > enqueue(std::string_view owner, std::string_view kind, std::string_view product, eve::Value context, double duration, int priority=0)
Enqueues a task and returns its stable ID.
Definition Production.cpp:216
int ownerTaskCount(std::string_view owner) const
Returns retained task count for an owner.
Definition Production.cpp:590
WorkQueue(const WorkQueue &)=delete
int slotCount(std::string_view owner) const
Returns an owner's slot count, defaulting to one.
Definition Production.cpp:92
eve::Result< void > pause(std::string_view taskId)
Pauses a queued or running task, or returns NotFound/Conflict.
Definition Production.cpp:345
eve::Result< void > fail(std::string_view taskId, std::string_view reason="failed")
Marks a non-terminal task failed with a structured outcome.
Definition Production.cpp:386
eve::OptionalRef< ProductionEvent > eventAt(int index)
Returns an event by sequence index, or an empty borrowed reference.
Definition Production.cpp:611
void clearEvents()
Clears retained events without resetting sequence numbering.
Definition Production.cpp:621
Definition QueueInspector.h:12
@ Completed
@ ReadyToSettle
@ Running
@ Cancelled
@ SettlementFailed
@ ShortestRemaining
@ ReadyToSettle
@ SettlementFailed
std::string_view eventKindName(ProductionEventKind kind)
Returns the stable lowercase name of an event kind.
Definition Production.cpp:70
std::string_view taskStateName(TaskState state)
Returns the stable lowercase name of a task state.
Definition Production.cpp:56
RefundPolicy
Reservation refund rule applied when work terminates before settlement.
Definition Production.h:74
@ InvalidArgument
@ NotFound
@ PreconditionViolation
@ Conflict
@ NoOp
@ Applied
std::optional< std::reference_wrapper< T > > OptionalRef
Optional borrowed reference; it does not extend T's lifetime.
Definition BorrowedRef.h:24
std::vector< std::string > prerequisites
Definition Production.h:61
std::vector< std::string > blocks
Definition Production.h:62
std::vector< std::string > requiredTags
Definition Production.h:64
std::vector< eve::definition::DefinitionHandle > requiredDefinitions
Definition Production.h:63
int maintainStockTarget
Definition Production.h:101
Validated input used to create a domain-neutral production task.
Definition Production.h:137
Owning proof that a domain consumer published one task exactly once.
Definition Production.h:46
std::string settlementId
Definition Production.h:47
A subject-agnostic continuous task retained for audit and save games.
Definition Production.h:158
ReservationState reservationState
Definition Production.h:169
eve::definition::DefinitionHandle definition
Definition Production.h:167
ProductionDependencies dependencies
Definition Production.h:173
std::uint32_t refundPermille
Definition Production.h:184
ProductionTerminationPolicy termination
Definition Production.h:175
std::vector< ProductionResourceRequirement > resources
Definition Production.h:174
std::uint32_t efficiencyPermille
Definition Production.h:181
bool settlementRequired
Definition Production.h:185
std::string lastSettlementId
Definition Production.h:172
ProductionSettlementReceipt settlement
Definition Production.h:171
RefundPolicy cancellation
Definition Production.h:125
RefundPolicy failure
Definition Production.h:126
Deterministic externally supplied work contribution.
Definition Production.h:130
std::uint32_t efficiencyPermille
Definition Production.h:133