21
|
1 |
#!/usr/bin/env python3
|
|
2 |
|
|
3 |
import logging
|
|
4 |
import time
|
|
5 |
|
22
|
6 |
from config import Config
|
21
|
7 |
from pgtoolkit import pgmanager
|
|
8 |
from pgtoolkit.delayedquery import DelayedQuery
|
|
9 |
|
|
10 |
|
|
11 |
if __name__ == '__main__':
|
|
12 |
cfg = Config('tests.conf')
|
|
13 |
|
|
14 |
pgm = pgmanager.get_instance()
|
|
15 |
pgm.create_conn(isolation_level = 'autocommit', **cfg)
|
|
16 |
|
|
17 |
handler = logging.StreamHandler()
|
|
18 |
logger = logging.getLogger('pgmanager')
|
|
19 |
logger.addHandler(handler)
|
|
20 |
logger.setLevel(logging.DEBUG)
|
|
21 |
|
|
22 |
dq = DelayedQuery(pgm)
|
|
23 |
|
|
24 |
print('add 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)
|
|
27 |
print('after 1')
|
|
28 |
|
|
29 |
time.sleep(5)
|
|
30 |
|
|
31 |
print('add 2')
|
|
32 |
dq.add(10, 'INSERT INTO test (name) VALUES (%s)', ['spam2'])
|
|
33 |
|
|
34 |
time.sleep(5)
|
|
35 |
print('after 10')
|
|
36 |
|
|
37 |
time.sleep(10)
|