Implement idempotent command tracking with TTL for improved command handling
This commit is contained in:
@@ -28,6 +28,34 @@ local BROADCAST_INTERVAL = 1 -- seconds between state broadcasts
|
||||
local CRAFT_CHANNEL = 4203
|
||||
local CRAFT_REPLY_CHANNEL = 4204
|
||||
|
||||
-------------------------------------------------
|
||||
-- Idempotent command tracking
|
||||
-------------------------------------------------
|
||||
|
||||
local processedCmdIds = {} -- commandId -> os.epoch("utc") ms
|
||||
local CMD_TTL_MS = 300000 -- 5 minutes
|
||||
|
||||
local function isCommandDuplicate(commandId)
|
||||
if not commandId then return false end
|
||||
local entry = processedCmdIds[commandId]
|
||||
if entry and (os.epoch("utc") - entry) < CMD_TTL_MS then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function recordCommandId(commandId)
|
||||
if not commandId then return end
|
||||
processedCmdIds[commandId] = os.epoch("utc")
|
||||
end
|
||||
|
||||
local function cleanupCommandIds()
|
||||
local cutoff = os.epoch("utc") - CMD_TTL_MS
|
||||
for id, ts in pairs(processedCmdIds) do
|
||||
if ts < cutoff then processedCmdIds[id] = nil end
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------
|
||||
-- Load config from file if present
|
||||
-------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user