From d86413ad81135454df7ef1c7d7faeb52eb51efa8 Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Wed, 1 Feb 2023 12:24:22 +0100 Subject: adding some common stuff, less code replica --- queue2pgsql.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'queue2pgsql.py') diff --git a/queue2pgsql.py b/queue2pgsql.py index 0c95f6d..253f5b4 100644 --- a/queue2pgsql.py +++ b/queue2pgsql.py @@ -1,23 +1,25 @@ #!/usr/bin/env python3 +''' move items from queue to database ''' import os import time import pickle import sqlite3 from litequeue import SQLQueue -from datetime import datetime -from todb import todb +from common import dbi + +QUEUE_DB = os.environ.get('el_QUEUE_db', 'litequeue.db') # Unlock all -con = sqlite3.connect("litequeue.db") +con = sqlite3.connect(QUEUE_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 = SQLQueue(QUEUE_DB, maxsize=None) q.prune() # Event loop @@ -28,7 +30,7 @@ while True: continue task = q.pop() raw = pickle.loads(task['message']) - todb(raw[0],raw[1]) + dbi(raw[0],raw[1]) print("Processed " + str(task['message_id']) + ". " + str(q.qsize() - 1) + " left") q.done(task['message_id']) -- cgit v1.2.3