diff options
Diffstat (limited to 'nopsyncd/qlistener.lua')
-rwxr-xr-x | nopsyncd/qlistener.lua | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/nopsyncd/qlistener.lua b/nopsyncd/qlistener.lua index 9498fbb..b7c74d8 100755 --- a/nopsyncd/qlistener.lua +++ b/nopsyncd/qlistener.lua @@ -22,7 +22,8 @@ local queue_name = "/rhnop" mq = require "luamq" -db = require "db" +tempstorage = require "tempstorage" +rddb = require "rddb" function main_loop() local q, err = mq.create(queue_name, "ro") @@ -31,9 +32,16 @@ function main_loop() os.exit(1) end - local ret, err = db:init() + local ret, err = tempstorage:init() if ret == nil then - io.stderr:write("creation of db failed: " .. err .. "\n") + io.stderr:write("creation of tempstorage failed: " .. err .. "\n") + os.exit(1) + end + + local ret, err = rddb:init() + if ret == nil then + io.stderr:write("opening rivendell db failed: " .. err .. "\n") + tempstorage:close() os.exit(1) end @@ -41,6 +49,8 @@ function main_loop() local msg, prio = mq.receive(q) if msg == nil then io.stderr:write("recv error: " .. prio .. "\n") + rddb:close() + tempstorage:close() os.exit(2) end @@ -48,9 +58,14 @@ function main_loop() if not timestamp or not nowcart or not nowlen or not nextcart or not nextlen then io.stderr:write("ignoring malformed message\n") else - -- TODO: lookup info in Rivendell DB and insert into temporary storage - print("received message:\ntimestamp = " .. timestamp .. "\nnowcart = " .. nowcart .. "\nnowlen = " .. nowlen .. "\nnextcart = " .. nextcart .. "\nnextlen = " .. nextlen) - pipe.signal() + local results, err = rddb:getCartInfo(nowcart); + if results == nil then + io.stderr:write("can't fetch cart info: " .. err .. "\n") + else + -- TODO: insert into tempstorage + print(timestamp .. " Info: '" .. results.TITLE .. "' von '" .. results.ARTIST .. "' aus '" .. results.ALBUM .. "'") + pipe.signal() + end end end -end
\ No newline at end of file +end
\ No newline at end of file |