diff options
Diffstat (limited to 'queue2pgsql.py')
-rw-r--r-- | queue2pgsql.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/queue2pgsql.py b/queue2pgsql.py new file mode 100644 index 0000000..0c95f6d --- /dev/null +++ b/queue2pgsql.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +import os +import time +import pickle +import sqlite3 +from litequeue import SQLQueue +from datetime import datetime + +from todb import todb + +# Unlock all +con = sqlite3.connect("litequeue.db") +cur = con.cursor() +cur.execute("UPDATE Queue SET status = 0 WHERE status = 1") +con.commit() +con.close() + +# Open Queue +q = SQLQueue("litequeue.db", maxsize=None) +q.prune() + +# Event loop +while True: + if q.empty() == True: + print("Queue empty. Sleeping 10s") + time.sleep(10) + continue + task = q.pop() + raw = pickle.loads(task['message']) + todb(raw[0],raw[1]) + print("Processed " + str(task['message_id']) + ". " + str(q.qsize() - 1) + " left") + q.done(task['message_id']) + +print("END") |