Skip to content

Commit

Permalink
save-update enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Dec 31, 2021
1 parent daf58d8 commit 43473b5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
9 changes: 7 additions & 2 deletions autosave.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ local function worker()
for _, entry in pairs(list) do
local autosave_hash = entry.data
local ctx = autosave_controllers[autosave_hash]
ctx.update_count = ctx.update_count + 1
blockexchange.save_update_area(ctx.owner, ctx.pos1, ctx.pos2, pos1, pos2, ctx.username, ctx.schema.name)
blockexchange.save_update_area(
ctx.owner, ctx.pos1, ctx.pos2, pos1, pos2,
ctx.username, ctx.schema.name):next(function(total_parts)
ctx.update_count = ctx.update_count + total_parts
end):catch(function(err_msg)
minetest.chat_send_player(ctx.playername, minetest.colorize("#ff0000", err_msg))
end)
end
end

Expand Down
2 changes: 1 addition & 1 deletion commands/save_update.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function blockexchange.save_update(playername, origin, pos1, pos2, username, sch
ctx.promise:reject(err)
end)

return ctx.promise
return ctx.promise, ctx
end

-- update a region of a schema
Expand Down
16 changes: 9 additions & 7 deletions worker/save_update_worker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ function blockexchange.save_update_worker(ctx)
blockexchange.api.create_schemamods(ctx.token, ctx.schema.id, mod_names):next(function()
local msg = "[blockexchange] Save-update complete with " .. ctx.total_parts .. " parts"
minetest.log("action", msg)
minetest.chat_send_player(ctx.playername, msg)
ctx.promise:resolve(ctx.total_parts)
end):catch(function(http_code)
local msg = "[blockexchange] mod-update failed with http code: " .. (http_code or "unkown")
minetest.log("error", msg)
minetest.chat_send_player(ctx.playername, minetest.colorize("#ff0000", msg))
ctx.promise:reject(msg)
end)
return
end
Expand All @@ -48,11 +47,15 @@ function blockexchange.save_update_worker(ctx)
local relative_pos = vector.subtract(ctx.current_pos, ctx.origin)

if air_only then
-- don't save air-only
minetest.log("action", "[blockexchange] NOT Saving part " .. minetest.pos_to_string(ctx.current_pos) ..
-- delete air-only parts in the remote repository
minetest.log("action", "[blockexchange] Deleting part " .. minetest.pos_to_string(ctx.current_pos) ..
" because it is air-only (processing took " .. diff .. " micros)")
shift(ctx)
minetest.after(blockexchange.min_delay, blockexchange.save_update_worker, ctx)
blockexchange.api.remove_schemapart(ctx.token, ctx.schema.id, relative_pos):next(function()
shift(ctx)
minetest.after(blockexchange.min_delay, blockexchange.save_update_worker, ctx)
end):catch(function(err_msg)
ctx.promise:reject(err_msg)
end)
else
-- package data properly over the wire
local metadata = minetest.write_json({
Expand Down Expand Up @@ -84,7 +87,6 @@ function blockexchange.save_update_worker(ctx)
local msg = "[blockexchange] create schemapart failed with http code: " .. (http_code or "unkown") ..
" retrying..."
minetest.log("error", msg)
minetest.chat_send_player(ctx.playername, minetest.colorize("#ff0000", msg))
-- wait a couple seconds
minetest.after(5, blockexchange.save_update_worker, ctx)
end)
Expand Down

0 comments on commit 43473b5

Please sign in to comment.