diff options
author | Christian Pointner <equinox@helsinki.at> | 2017-01-06 21:49:35 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2017-01-06 21:49:35 (GMT) |
commit | 52680074ae2143b5d92e1c99c36a53d4a9c01471 (patch) | |
tree | ae2251bd6bc8ee0acfec05d2e50efc69188755b1 /src/qlistener.lua | |
parent | df67f85aafb91466bcd63681ebf4f6d9b3b6e8be (diff) |
fix last cart check
Diffstat (limited to 'src/qlistener.lua')
-rw-r--r-- | src/qlistener.lua | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/qlistener.lua b/src/qlistener.lua index 86004ee..5e31890 100644 --- a/src/qlistener.lua +++ b/src/qlistener.lua @@ -19,7 +19,7 @@ -- along with rhnop. If not, see <http://www.gnu.org/licenses/>. -- -local last_cart = nil +local last_carts = nil posix = require "posix" mq = require "mq" @@ -59,18 +59,19 @@ function handle_now(timestamp, nowcart, nowlen) end function handle_message(msg, q) - local timestamp, nowcart, nowlen, nextcart, nextlen = string.match(msg, "^(%d+) (%d+) (%d+) (%d+) (%d+)$"); - if not timestamp or not nowcart or not nowlen or not nextcart or not nextlen then + local timestamp, output, nowcart, nowlen, nextcart, nextlen = string.match(msg, "^(%d+) (%d+) (%d+) (%d+) (%d+) (%d+)$"); + if not timestamp or not output or not nowcart or not nowlen or not nextcart or not nextlen then io.stderr:write("WARN: ignoring malformed message\n") else nowcart = tonumber(nowcart) nowlen = tonumber(nowlen) - if last_cart ~= nowcart and nowlen > 0 then - last_cart = nowcart + if last_carts[output] == nil then last_carts[output] = 0 end + if last_carts[output] ~= nowcart and nowlen > 0 then + last_carts[output] = nowcart local ret = handle_now(timestamp, nowcart, nowlen) if ret == nil then io.stderr:write("INFO: trying to push last message back onto the queue - before exiting\n") - local result, err = mq.send(q, timestamp .. " " .. nowcart .. " " .. nowlen .. " " .. nextcart .. " " .. nextlen, 0) + local result, err = mq.send(q, timestamp .. " " .. output .. " " .. nowcart .. " " .. nowlen .. " " .. nextcart .. " " .. nextlen, 0) if result == nil then io.stderr:write("ERROR: sending message failed: " .. err .. "\n") end @@ -100,7 +101,7 @@ function main_loop() io.stderr:write("ERROR: creation of playlog failed: " .. err .. "\n") os.exit(1) end - last_cart = assert(playlog:getLastCart()) + last_carts = assert(playlog:getLastCarts()) print("PLAYLOG: connected to " .. cnf.playlog_db .. "@" .. cnf.playlog_host .. " with user '" .. cnf.playlog_user .. "'") local ret, err = rddb:init(cnf) |