fix(udsendelse): retfærdig kø i udsendelsesporten — længst ventende sender næste maskine ud (v1.62.239)
This commit is contained in:
@@ -343,6 +343,7 @@ local function farmVehiclesById(adEnv)
|
||||
end
|
||||
|
||||
local restartDue = {} -- runId -> ms hvor næste tjek for ledige traktorer må køre
|
||||
local restartWaiting = {} -- runId -> true mens en ledig traktor med arbejde står i udsendelsesportens kø
|
||||
local lastControlled = setmetatable({}, {__mode = "k"}) -- køretøj -> ms hvor spilleren sidst sad i den
|
||||
|
||||
local function restartIdleMember(adEnv, run, byId, now)
|
||||
@@ -353,9 +354,10 @@ local function restartIdleMember(adEnv, run, byId, now)
|
||||
end
|
||||
if restartDue[run.id] == nil then restartDue[run.id] = now + ADFlowSleep.RESTART_STARTUP_DELAY_MS end
|
||||
if now < restartDue[run.id] then return end
|
||||
-- fælles udsendelsesport lukket: prøv igen ved næste tick (uden at skubbe minut-tjekket)
|
||||
if ADLaunchGate ~= nil and not ADLaunchGate.isOpen() then return end
|
||||
restartDue[run.id] = now + ADFlowSleep.WAKE_CHECK_MS
|
||||
local gateName = "flow:" .. tostring(run.id)
|
||||
-- står allerede i portens kø: regn ikke det hele igen hvert sekund, før det er vores tur
|
||||
if restartWaiting[run.id] and ADLaunchGate ~= nil and not ADLaunchGate.isOpen(gateName) then return end
|
||||
restartWaiting[run.id] = nil
|
||||
for _, id in ipairs(run.vehicleIds or {}) do
|
||||
local vehicle = byId[id]
|
||||
if vehicle ~= nil then
|
||||
@@ -370,13 +372,25 @@ local function restartIdleMember(adEnv, run, byId, now)
|
||||
end
|
||||
end
|
||||
local id = ADFlowSleep.pickIdleMember(run, members)
|
||||
if id == nil then return end
|
||||
local hasWork, why = ADFlowSleep.hasWork(adEnv, run, byId, id)
|
||||
if not hasWork then return end
|
||||
local hasWork, why = false, nil
|
||||
if id ~= nil then hasWork, why = ADFlowSleep.hasWork(adEnv, run, byId, id) end
|
||||
if not hasWork then
|
||||
restartDue[run.id] = now + ADFlowSleep.WAKE_CHECK_MS
|
||||
if ADLaunchGate ~= nil then ADLaunchGate.done(gateName) end
|
||||
return
|
||||
end
|
||||
-- fælles udsendelsesport: står i kø og prøver igen ved næste tick (uden at skubbe minut-tjekket)
|
||||
if ADLaunchGate ~= nil and not ADLaunchGate.isOpen(gateName) then
|
||||
restartWaiting[run.id] = true
|
||||
return
|
||||
end
|
||||
restartDue[run.id] = now + ADFlowSleep.WAKE_CHECK_MS
|
||||
Logging.info(ADFlowSleep.LOG_PREFIX .. "'%s': '%s' holder stille i det kørende flow — startes (%s)", tostring(run.name),
|
||||
tostring(ADRuns.vehicleLabel(byId[id])), tostring(why))
|
||||
local result = ADRunsController.startVehicle(adEnv, run, byId[id])
|
||||
if ADLaunchGate ~= nil and result ~= nil and result.ok then ADLaunchGate.markLaunched() end
|
||||
if ADLaunchGate ~= nil then
|
||||
if result ~= nil and result.ok then ADLaunchGate.markLaunched(gateName) else ADLaunchGate.done(gateName) end
|
||||
end
|
||||
if ADFlowSleep.restartNeedsBackoff(result) then restartDue[run.id] = now + ADFlowSleep.RESTART_FAILED_BACKOFF_MS end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user