milo: better perf when storage is full
This commit is contained in:
@@ -161,6 +161,7 @@ Event.on({ 'milo_cycle', 'milo_queue' }, function(e)
|
|||||||
end
|
end
|
||||||
context.taskTimer = context.taskTimer + taskTimer()
|
context.taskTimer = context.taskTimer + taskTimer()
|
||||||
context.taskCounter = context.taskCounter + 1
|
context.taskCounter = context.taskCounter + 1
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if context.storage:isOnline() and #context.queue > 0 then
|
if context.storage:isOnline() and #context.queue > 0 then
|
||||||
@@ -176,8 +177,14 @@ Event.on('turtle_inventory', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
Event.onInterval(5, function()
|
local cycleHandle
|
||||||
|
cycleHandle = Event.onInterval(5, function()
|
||||||
Event.trigger('milo_cycle')
|
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)
|
end)
|
||||||
|
|
||||||
Event.on({ 'storage_offline', 'storage_online' }, function()
|
Event.on({ 'storage_offline', 'storage_online' }, function()
|
||||||
|
|||||||
@@ -55,7 +55,9 @@ function ImportTask:cycle(context)
|
|||||||
return node.adapter.getItemMeta(slotNo)
|
return node.adapter.getItemMeta(slotNo)
|
||||||
end)
|
end)
|
||||||
if item and matchesFilter(item) then
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -72,6 +74,9 @@ function ImportTask:cycle(context)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function tasks:onError(msg)
|
||||||
|
_G._debug('IMPORT error: ' .. msg)
|
||||||
|
end
|
||||||
tasks:run()
|
tasks:run()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -12,16 +12,13 @@ function InputChest:cycle(context)
|
|||||||
})
|
})
|
||||||
|
|
||||||
for node in context.storage:filterActive('input') do
|
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
|
for slot, item in pairs(node.adapter.list()) do
|
||||||
tasks:add(function()
|
if context.storage:import(node, slot, item.count, item) ~= item.count then
|
||||||
context.storage:import(node, slot, item.count, item)
|
break
|
||||||
end)
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
if not s and m then
|
|
||||||
_G._debug('INPUT error: ' .. m)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
tasks:run()
|
tasks:run()
|
||||||
|
|||||||
Reference in New Issue
Block a user