Only use amqp_prefix as config

This way we can easily have common config between the instance (in this
case socket_timeout, which is default 0.25 and way too low for
provo->NBG)
This commit is contained in:
Stephan Kulow 2018-11-24 14:19:00 +01:00
parent b350abaf5a
commit 798dbcd66e
2 changed files with 14 additions and 9 deletions

View File

@ -16,7 +16,7 @@ class PubSubConsumer(object):
"""
def __init__(self, amqp_url, logger):
def __init__(self, amqp_prefix, logger):
"""Create a new instance of the consumer class, passing in the AMQP
URL used to connect to RabbitMQ.
@ -27,7 +27,7 @@ class PubSubConsumer(object):
self._channel = None
self._closing = False
self._consumer_tag = None
self._url = amqp_url
self._prefix = amqp_prefix
self.logger = logger
def connect(self):
@ -38,8 +38,15 @@ class PubSubConsumer(object):
:rtype: pika.SelectConnection
"""
self.logger.info('Connecting to %s', self._url)
return pika.SelectConnection(pika.URLParameters(self._url),
self.logger.info('Connecting to %s', self._prefix)
account = 'opensuse'
server = 'rabbit.opensuse.org'
if self._prefix == 'suse':
account = 'suse'
server = 'rabbit.suse.de'
credentials = pika.PlainCredentials(account, account)
parameters = pika.ConnectionParameters(server, 5671, '/', credentials, ssl=True, socket_timeout=10)
return pika.SelectConnection(parameters,
self.on_connection_open,
stop_ioloop_on_close=False)

View File

@ -160,8 +160,8 @@ class Project(object):
class Listener(PubSubConsumer):
def __init__(self, amqp_prefix, amqp_url, openqa_url):
super(Listener, self).__init__(amqp_url, logging.getLogger(__name__))
def __init__(self, amqp_prefix, openqa_url):
super(Listener, self).__init__(amqp_prefix, logging.getLogger(__name__))
self.projects = []
self.amqp_prefix = amqp_prefix
self.openqa_url = openqa_url
@ -249,16 +249,14 @@ if __name__ == '__main__':
if apiurl.endswith('suse.de'):
amqp_prefix = 'suse'
amqp_url = "amqps://suse:suse@rabbit.suse.de"
openqa_url = 'https://openqa.suse.de'
else:
amqp_prefix = 'opensuse'
amqp_url = "amqps://opensuse:opensuse@rabbit.opensuse.org"
openqa_url = 'https://openqa.opensuse.org'
logging.basicConfig(level=logging.INFO)
l = Listener(amqp_prefix, amqp_url, openqa_url)
l = Listener(amqp_prefix, openqa_url)
url = makeurl(apiurl, ['search', 'project', 'id'], {'match': 'attribute/@name="OSRT:OpenQAMapping"'})
f = http_GET(url)
root = ET.parse(f).getroot()