tests/delayedquery.py
changeset 21 26209e9984b2
child 22 680631f35d83
equal deleted inserted replaced
20:73f0d53fef6b 21:26209e9984b2
       
     1 #!/usr/bin/env python3
       
     2 
       
     3 import logging
       
     4 import time
       
     5 
       
     6 from pgtoolkit import pgmanager
       
     7 from pgtoolkit.delayedquery import DelayedQuery
       
     8 
       
     9 
       
    10 class Config(dict):
       
    11     def __init__(self, fname):
       
    12         data = open(fname).read()
       
    13         exec(data, dict(), self)
       
    14 
       
    15 
       
    16 if __name__ == '__main__':
       
    17     cfg = Config('tests.conf')
       
    18     
       
    19     pgm = pgmanager.get_instance()
       
    20     pgm.create_conn(isolation_level = 'autocommit', **cfg)
       
    21     
       
    22     handler = logging.StreamHandler()
       
    23     logger = logging.getLogger('pgmanager')
       
    24     logger.addHandler(handler)
       
    25     logger.setLevel(logging.DEBUG)
       
    26 
       
    27     dq = DelayedQuery(pgm)
       
    28     
       
    29     print('add 1')
       
    30     dq.add(10, 'INSERT INTO test (name) VALUES (%s)', ['spam1'], queryid=1)
       
    31     dq.add(10, 'INSERT INTO test (name) VALUES (%s)', ['spam1'], queryid=1)
       
    32     print('after 1')
       
    33     
       
    34     time.sleep(5)
       
    35     
       
    36     print('add 2')
       
    37     dq.add(10, 'INSERT INTO test (name) VALUES (%s)', ['spam2'])
       
    38     
       
    39     time.sleep(5)
       
    40     print('after 10')
       
    41 
       
    42     time.sleep(10)