Package pgq :: Module event
[frames] | no frames]

Source Code for Module pgq.event

 1   
 2  """PgQ event container. 
 3  """ 
 4   
 5  __all__ = ('EV_RETRY', 'EV_DONE', 'EV_FAILED', 'Event') 
 6   
 7  # Event status codes 
 8  EV_RETRY = 0 
 9  EV_DONE = 1 
10  EV_FAILED = 2 
11   
12  _fldmap = { 
13          'ev_id': 'ev_id', 
14          'ev_txid': 'ev_txid', 
15          'ev_time': 'ev_time', 
16          'ev_type': 'ev_type', 
17          'ev_data': 'ev_data', 
18          'ev_extra1': 'ev_extra1', 
19          'ev_extra2': 'ev_extra2', 
20          'ev_extra3': 'ev_extra3', 
21          'ev_extra4': 'ev_extra4', 
22   
23          'id': 'ev_id', 
24          'txid': 'ev_txid', 
25          'time': 'ev_time', 
26          'type': 'ev_type', 
27          'data': 'ev_data', 
28          'extra1': 'ev_extra1', 
29          'extra2': 'ev_extra2', 
30          'extra3': 'ev_extra3', 
31          'extra4': 'ev_extra4', 
32  } 
33   
34 -class Event(object):
35 """Event data for consumers. 36 37 Consumer is supposed to tag them after processing. 38 If not, events will stay in retry queue. 39 """
40 - def __init__(self, queue_name, row):
41 self._event_row = row 42 self.status = EV_RETRY 43 self.retry_time = 60 44 self.fail_reason = "Buggy consumer" 45 self.queue_name = queue_name
46
47 - def __getattr__(self, key):
48 return self._event_row[_fldmap[key]]
49
50 - def tag_done(self):
51 self.status = EV_DONE
52
53 - def tag_retry(self, retry_time = 60):
54 self.status = EV_RETRY 55 self.retry_time = retry_time
56
57 - def tag_failed(self, reason):
58 self.status = EV_FAILED 59 self.fail_reason = reason
60