diff options
author | Dennis Eriksen <d@ennis.no> | 2023-02-01 12:24:22 +0100 |
---|---|---|
committer | Dennis Eriksen <d@ennis.no> | 2023-02-01 12:24:22 +0100 |
commit | d86413ad81135454df7ef1c7d7faeb52eb51efa8 (patch) | |
tree | faf9e7cc5bc728065f4d87f86db7c8b190ba42ed /queue2pgsql.py | |
parent | use new db thingy (diff) | |
download | energyscripts-d86413ad81135454df7ef1c7d7faeb52eb51efa8.tar.gz |
adding some common stuff, less code replica
Diffstat (limited to 'queue2pgsql.py')
-rw-r--r-- | queue2pgsql.py | 12 |
1 files changed, 7 insertions, 5 deletions
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']) |