From 9cf630000beb7146147f60c08d8424bc42d4c003 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Mon, 22 Apr 2019 15:15:27 -0400 Subject: [PATCH] milo: better perf when storage is full --- milo/MiloLocal.lua | 9 ++++++++- milo/plugins/importTask.lua | 7 ++++++- milo/plugins/inputChestTask.lua | 11 ++++------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/milo/MiloLocal.lua b/milo/MiloLocal.lua index 79f6b97..f276135 100644 --- a/milo/MiloLocal.lua +++ b/milo/MiloLocal.lua @@ -161,6 +161,7 @@ Event.on({ 'milo_cycle', 'milo_queue' }, function(e) end context.taskTimer = context.taskTimer + taskTimer() context.taskCounter = context.taskCounter + 1 + end if context.storage:isOnline() and #context.queue > 0 then @@ -176,8 +177,14 @@ Event.on('turtle_inventory', function() end) end) -Event.onInterval(5, function() +local cycleHandle +cycleHandle = Event.onInterval(5, function() Event.trigger('milo_cycle') + if context.taskCounter > 0 then + --local average = context.taskTimer / context.taskCounter + --_debug('Interval: ' .. math.max(5, 2 + average * 3)) + --cycleHandle.updateInterval(math.max(5, 2 + average * 3)) + end end) Event.on({ 'storage_offline', 'storage_online' }, function() diff --git a/milo/plugins/importTask.lua b/milo/plugins/importTask.lua index 1ec1568..6b868d3 100644 --- a/milo/plugins/importTask.lua +++ b/milo/plugins/importTask.lua @@ -55,7 +55,9 @@ function ImportTask:cycle(context) return node.adapter.getItemMeta(slotNo) end) if item and matchesFilter(item) then - context.storage:import(node, slotNo, item.count, item) + if context.storage:import(node, slotNo, item.count, item) ~= item.count then + error('Failed to import %s', item.name) + end end end @@ -72,6 +74,9 @@ function ImportTask:cycle(context) end) end + function tasks:onError(msg) + _G._debug('IMPORT error: ' .. msg) + end tasks:run() end diff --git a/milo/plugins/inputChestTask.lua b/milo/plugins/inputChestTask.lua index 1190dd0..fd306ed 100644 --- a/milo/plugins/inputChestTask.lua +++ b/milo/plugins/inputChestTask.lua @@ -12,16 +12,13 @@ function InputChest:cycle(context) }) for node in context.storage:filterActive('input') do - local s, m = pcall(function() + tasks:add(function() for slot, item in pairs(node.adapter.list()) do - tasks:add(function() - context.storage:import(node, slot, item.count, item) - end) + if context.storage:import(node, slot, item.count, item) ~= item.count then + break + end end end) - if not s and m then - _G._debug('INPUT error: ' .. m) - end end tasks:run()