aboutsummaryrefslogblamecommitdiffstats
path: root/scripts/common/queue.py
blob: 35abeaaab940d967ef9f41732e2dd40e87a9ff7f (plain) (tree)
1
2
3
4
5
6
7
8



                                  
             
              

                              



                                                          
 

                                 



                                    
                             
                               

                                                                       
                                            

                                      
                                   

                                                             
                                                                               
               
#!/usr/bin/env python3
''' common functions and stuff '''

import os
import pickle
import logging
from litequeue import SQLQueue

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

QUEUE_DB  = QUEUE_DIR + "/" + QUEUE_DB

log = logging.getLogger(__name__)

# Initialize queue
q = SQLQueue(QUEUE_DB, maxsize=None)

def dbi(sql,values,**kwargs):
    ''' insert into queue '''
    log.debug('function dbi()')
    verbose = bool(kwargs['verbose']) if 'verbose' in kwargs else False

    log.debug('Inserting into sqlite-queue')
    q.put(pickle.dumps([sql, values]))
    if verbose is True:
        log.debug('verbose = True')
        table = sql.split(' ')[2]
        num = 1 if isinstance(values, tuple) else len(values)
        print("Inserted " + str(num) + " item(s) into queue for " + str(table))
    return True