1
2 """PgQ producer helpers for Python.
3 """
4
5 import skytools
6
7 _fldmap = {
8 'id': 'ev_id',
9 'time': 'ev_time',
10 'type': 'ev_type',
11 'data': 'ev_data',
12 'extra1': 'ev_extra1',
13 'extra2': 'ev_extra2',
14 'extra3': 'ev_extra3',
15 'extra4': 'ev_extra4',
16
17 'ev_id': 'ev_id',
18 'ev_time': 'ev_time',
19 'ev_type': 'ev_type',
20 'ev_data': 'ev_data',
21 'ev_extra1': 'ev_extra1',
22 'ev_extra2': 'ev_extra2',
23 'ev_extra3': 'ev_extra3',
24 'ev_extra4': 'ev_extra4',
25 }
26
28 q = "select pgq.current_event_table(%s)"
29 curs.execute(q, [queue_name])
30 tbl = curs.fetchone()[0]
31 db_fields = map(_fldmap.get, fields)
32 skytools.magic_insert(curs, tbl, rows, db_fields)
33
34 -def insert_event(curs, queue, ev_type, ev_data,
35 extra1=None, extra2=None,
36 extra3=None, extra4=None):
37 q = "select pgq.insert_event(%s, %s, %s, %s, %s, %s, %s)"
38 curs.execute(q, [queue, ev_type, ev_data,
39 extra1, extra2, extra3, extra4])
40 return curs.fetchone()[0]
41