Skip to content

Instantly share code, notes, and snippets.

@leandromoreira

leandromoreira/loop.lua

Last active Apr 13, 2020
Embed
What would you like to do?
--- fetch ---
local resp, err = redis_client:smembers("coding_units")
local raw_coding_units = {}
for _, coding_unit_key in ipairs(resp) do
local resp, err = redis_client:get(coding_unit_key) -- it'd be nice to keep the id for logging reasons
table.insert(raw_coding_units, resp)
end
--- fetch ---
--- parse ---
local coding_units = {}
for _, raw_coding_unit in ipairs(raw_coding_units) do
local parts = mysplit(raw_coding_unit, "||")
local cu = {}
cu['phase'] = parts[1]
cu['code'] = parts[2]
table.insert(coding_units, cu)
end
--- parse ---
--- execute ---
for _, coding_unit in ipairs(coding_units) do
if coding_unit['phase'] == 'current_phase' then
--- error checking omited ---
local function_code, err = loadstring(coding_unit['code'])
local status, ret = xpcall(function_code, err_handler)
end
end
--- execute ---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment