tests/delayedquery.py
changeset 78 64c62ac8f65d
parent 22 680631f35d83
child 104 d8ff52a0390f
equal deleted inserted replaced
77:2cfef775f518 78:64c62ac8f65d
     1 #!/usr/bin/env python3
     1 #!/usr/bin/env python3
     2 
     2 
     3 import logging
     3 import logging
     4 import time
     4 import time
     5 
     5 
     6 from config import Config
     6 from tests.config import Config
     7 from pgtoolkit import pgmanager
     7 from pgtoolkit import pgmanager
     8 from pgtoolkit.delayedquery import DelayedQuery
     8 from pgtoolkit.delayedquery import DelayedQuery
     9 
     9 
    10 
    10 
    11 if __name__ == '__main__':
    11 if __name__ == '__main__':
    12     cfg = Config('tests.conf')
    12     cfg = Config('tests.conf')
    13     
    13 
    14     pgm = pgmanager.get_instance()
    14     pgm = pgmanager.get_instance()
    15     pgm.create_conn(isolation_level = 'autocommit', **cfg)
    15     pgm.create_conn(isolation_level = 'autocommit', **cfg)
    16     
    16 
    17     handler = logging.StreamHandler()
    17     handler = logging.StreamHandler()
    18     logger = logging.getLogger('pgmanager')
    18     logger = logging.getLogger('pgmanager')
    19     logger.addHandler(handler)
    19     logger.addHandler(handler)
    20     logger.setLevel(logging.DEBUG)
    20     logger.setLevel(logging.DEBUG)
    21 
    21 
    22     dq = DelayedQuery(pgm)
    22     dq = DelayedQuery(pgm)
    23     
    23 
    24     print('add 1')
    24     print('add 1')
    25     dq.add(10, 'INSERT INTO test (name) VALUES (%s)', ['spam1'], queryid=1)
    25     dq.add(10, 'INSERT INTO test (name) VALUES (%s)', ['spam1'], queryid=1)
    26     dq.add(10, 'INSERT INTO test (name) VALUES (%s)', ['spam1'], queryid=1)
    26     dq.add(10, 'INSERT INTO test (name) VALUES (%s)', ['spam1'], queryid=1)
    27     print('after 1')
    27     print('after 1')
    28     
    28 
    29     time.sleep(5)
    29     time.sleep(5)
    30     
    30 
    31     print('add 2')
    31     print('add 2')
    32     dq.add(10, 'INSERT INTO test (name) VALUES (%s)', ['spam2'])
    32     dq.add(10, 'INSERT INTO test (name) VALUES (%s)', ['spam2'])
    33     
    33 
    34     time.sleep(5)
    34     time.sleep(5)
    35     print('after 10')
    35     print('after 10')
    36 
    36 
    37     time.sleep(10)
    37     time.sleep(10)