aboutsummaryrefslogtreecommitdiffstats
path: root/queue2pgsql.py
blob: 253f5b43b485f65f3ba414caee4b40a8d2fff6d2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
''' move items from queue to database '''

import os
import time
import pickle
import sqlite3
from litequeue import SQLQueue

from common import dbi

QUEUE_DB = os.environ.get('el_QUEUE_db', 'litequeue.db')

# Unlock all
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(QUEUE_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'])
    dbi(raw[0],raw[1])
    print("Processed " + str(task['message_id']) + ". " + str(q.qsize() - 1) + " left")
    q.done(task['message_id'])

print("END")