Skip to content

Commit

Permalink
Statusbot: Error handling for temp-db write and added some debug mess…
Browse files Browse the repository at this point in the history
…ages
  • Loading branch information
hbeni committed Mar 6, 2024
1 parent 4ac8bf0 commit 428ce25
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions server/statuspage/fgcom-status.bot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Installation of this plugin is described in the projects readme: https://github.
]]

dofile("sharedFunctions.inc.lua") -- include shared functions
fgcom.botversion = "1.8.2"
fgcom.botversion = "1.8.3"
json = require("dkjson")
local botname = "FGCOM-Status"
fgcom.callsign = "FGCOM-Status"
Expand Down Expand Up @@ -173,6 +173,7 @@ local generateOutData = function()


-- generate metadata
fgcom.dbg("generateOutData(): generating highscore data...")
if highscore.num < users_alive then
highscore.num = users_alive
highscore.date = os.time()
Expand All @@ -182,6 +183,7 @@ local generateOutData = function()


-- generate JSON structure
fgcom.dbg("generateOutData(): generating db content...")
dataJsonString = json.encode(data)
fgcom.dbg("JSON RESULT: "..dataJsonString)
return dataJsonString
Expand Down Expand Up @@ -211,6 +213,7 @@ dbUpdateTimer_func = function(t)
fgcom.dbg("opened db '"..tmpdb.."'")
-- tmpdb is open, write out the data
local data = generateOutData()
fgcom.dbg("db data generating completed")
local writeRes = tmpdb_fh:write(data)
if not writeRes then
fgcom.log("unable to write into db: "..tmpdb)
Expand All @@ -223,9 +226,12 @@ dbUpdateTimer_func = function(t)
io.close(tmpdb_fh)

os.remove(db)
ren_rc, ren_message = os.rename(tmpdb, db)
-- TODO: handle errors
fgcom.dbg("published db '"..db.."'")
local ren_rc, ren_message = os.rename(tmpdb, db)
if not ren_rc then
fgcom.log("error publishing db: "..db)
else
fgcom.dbg("published db '"..db.."'")
end
end

-- clean up stale entries
Expand Down

0 comments on commit 428ce25

Please sign in to comment.