Package pgq :: Module consumer :: Class Consumer
[frames] | no frames]

Class Consumer

source code

                 object --+    
                          |    
skytools.scripting.DBScript --+
                              |
                             Consumer
Known Subclasses:
RemoteConsumer, SerialConsumer

Consumer base class.

Instance Methods
 
__init__(self, service_name, db_name, args)
Initialize new consumer.
source code
 
attach(self)
Attach consumer to interesting queues.
source code
 
detach(self)
Detach consumer from all queues.
source code
 
process_event(self, db, event)
Process one event.
source code
 
process_batch(self, db, batch_id, event_list)
Process all events in batch.
source code
 
work(self)
Do the work loop, once (internal).
source code
 
register_consumer(self, queue_name) source code
 
unregister_consumer(self, queue_name) source code
 
get_batch_info(self, batch_id)
Get info about batch.
source code
 
stat_start(self) source code
 
stat_end(self, count) source code

Inherited from skytools.scripting.DBScript: close_database, get_database, hook_sighup, hook_sigint, init_optparse, reload, reset, run, run_once, send_signal, send_stats, set_single_loop, start, startup, stat_add, stat_increase, stat_put, stop

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables

Inherited from skytools.scripting.DBScript: cf, job_name, log, service_name

Properties

Inherited from object: __class__

Method Details

__init__(self, service_name, db_name, args)
(Constructor)

source code 
Initialize new consumer.
Parameters:
  • service_name - service_name for DBScript
  • db_name - name of database for get_database()
  • args - cmdline args for DBScript
Overrides: skytools.scripting.DBScript.__init__

process_event(self, db, event)

source code 

Process one event.

Should be overrided by user code.

Event should be tagged as done, retry or failed. If not, it will be tagged as for retry.

process_batch(self, db, batch_id, event_list)

source code 

Process all events in batch.

By default calls process_event for each. Can be overrided by user code.

Events should be tagged as done, retry or failed. If not, they will be tagged as for retry.

work(self)

source code 
Do the work loop, once (internal).
Overrides: skytools.scripting.DBScript.work

get_batch_info(self, batch_id)

source code 
Get info about batch.
Returns:
Return value is a dict of:
  • queue_name: queue name
  • consumer_name: consumers name
  • batch_start: batch start time
  • batch_end: batch end time
  • tick_id: end tick id
  • prev_tick_id: start tick id
  • lag: how far is batch_end from current moment.