本文整理汇总了Python中pgq.consumer.Consumer类的典型用法代码示例。如果您正苦于以下问题:Python Consumer类的具体用法?Python Consumer怎么用?Python Consumer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Consumer类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register_consumer
def register_consumer(self, provider_loc = None):
"""Register consumer on source node first, then target node."""
if not provider_loc:
provider_loc = self.options.provider
if not provider_loc:
self.log.error('Please give provider location with --provider=')
sys.exit(1)
dst_db = self.get_database(self.target_db)
dst_curs = dst_db.cursor()
src_db = self.get_database(PDB, connstr = provider_loc)
src_curs = src_db.cursor()
# check target info
q = "select * from pgq_node.get_node_info(%s)"
res = self.exec_cmd(src_db, q, [ self.queue_name ])
pnode = res[0]['node_name']
if not pnode:
raise Exception('parent node not initialized?')
# source queue
Consumer.register_consumer(self)
# fetch pos
q = "select last_tick from pgq.get_consumer_info(%s, %s)"
src_curs.execute(q, [self.queue_name, self.consumer_name])
last_tick = src_curs.fetchone()['last_tick']
if not last_tick:
raise Exception('registration failed?')
src_db.commit()
# target node
q = "select * from pgq_node.register_consumer(%s, %s, %s, %s)"
self.exec_cmd(dst_db, q, [self.queue_name, self.consumer_name, pnode, last_tick])
示例2: exception_hook
def exception_hook(self, det, emsg):
try:
dst_db = self.get_database(self.target_db)
q = "select * from pgq_node.set_consumer_error(%s, %s, %s)"
self.exec_cmd(dst_db, q, [ self.queue_name, self.consumer_name, emsg ])
except:
self.log.warning("Failure to call pgq_node.set_consumer_error()")
self.reset()
Consumer.exception_hook(self, det, emsg)
示例3: unregister_consumer
def unregister_consumer(self):
dst_db = self.get_database(self.target_db)
state = self.get_consumer_state()
src_db = self.get_provider_db(state)
# unregister on provider
Consumer.unregister_consumer(self)
# unregister on subscriber
q = "select * from pgq_node.unregister_consumer(%s, %s)"
self.exec_cmd(dst_db, q, [ self.queue_name, self.consumer_name ])
示例4: __init__
def __init__(self, service_name, db_name, args):
"""Initialize new subconsumer.
@param service_name: service_name for DBScript
@param db_name: name of database for get_database()
@param args: cmdline args for DBScript
"""
Consumer.__init__(self, service_name, db_name, args)
self.subconsumer_name = self.cf.get("subconsumer_name")
示例5: __init__
def __init__(self, service_name, db_name, args):
"""Initialize new consumer.
@param service_name: service_name for DBScript
@param db_name: target database name for get_database()
@param args: cmdline args for DBScript
"""
Consumer.__init__(self, service_name, PDB, args)
self.log.debug("__init__")
self.target_db = db_name
self.provider_connstr = None
示例6: init_optparse
def init_optparse(self, parser = None):
p = Consumer.init_optparse(self, parser)
p.add_option("--rewind", action = "store_true",
help = "change queue position according to destination")
p.add_option("--reset", action = "store_true",
help = "reset queue pos on destination side")
return p
示例7: startup
def startup(self):
if self.options.rewind:
self.rewind()
sys.exit(0)
if self.options.reset:
self.dst_reset()
sys.exit(0)
return Consumer.startup(self)
示例8: unregister_consumer
def unregister_consumer(self):
dst_db = self.get_database(self.target_db)
dst_curs = dst_db.cursor()
# fetch provider loc
q = "select * from pgq_node.get_consumer_state(%s, %s)"
rows = self.exec_cmd(dst_db, q, [ self.queue_name, self.consumer_name ])
state = rows[0]
provider_loc = state['provider_location']
# unregister on provider
src_db = self.get_database(PDB, connstr = provider_loc)
src_curs = src_db.cursor()
Consumer.unregister_consumer(self)
# unregister on subscriber
q = "select * from pgq_node.unregister_consumer(%s, %s)"
self.exec_cmd(dst_db, q, [ self.queue_name, self.consumer_name ])
示例9: work
def work(self):
"""Refresh state before calling Consumer.work()."""
dst_db = self.get_database(self.target_db)
self._consumer_state = self.refresh_state(dst_db)
if self._consumer_state['node_type'] == 'root':
self.process_root_node(dst_db)
return
if not self.provider_connstr:
raise Exception('provider_connstr not set')
src_db = self.get_database('_provider_db', connstr = self.provider_connstr)
return Consumer.work(self)
示例10: init_optparse
def init_optparse(self, parser = None):
p = Consumer.init_optparse(self, parser)
p.add_option("--provider", help = "provider location for --register")
return p
示例11: __init__
def __init__(self, service_name, db_name, remote_db, args):
Consumer.__init__(self, service_name, db_name, args)
self.remote_db = remote_db
self.dst_schema = "pgq_ext"
self.cur_batch_info = None
示例12: unregister_consumer
def unregister_consumer(self):
"""If unregistering, also clean completed tick table on dest."""
Consumer.unregister_consumer(self)
self.dst_reset()
示例13: register_consumer
def register_consumer(self):
new = Consumer.register_consumer(self)
if new: # fixme
self.dst_reset()