Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try:
dbconn = psycopg2.connect(args.dsn)
except psycopg2.OperationalError:
time.sleep(0.1)
user, password = read_credentials()
unique_label = 'autoland-%s' % platform.node()
pulse = consumers.BuildConsumer(applabel=unique_label, user=user,
password=password)
pulse.configure(topic=['build.#.finished'], callback=handle_message)
logger.debug('applabel: %s' % unique_label)
while True:
try:
pulse.listen()
except amqp.exceptions.ConnectionForced as e:
logger.error('pulse error: ' + str(e))
except IOError as e:
logger.error('pulse error: ' + str(e))
while self.is_running:
try:
conn.drain_events(timeout=1)
except socket.timeout:
pass
except KeyboardInterrupt:
self.stop()
LOG.info(
"Server with id='{}' stopped."
.format(self.server_id)
)
return
except (socket.error, amqp.exceptions.ConnectionForced) as e:
LOG.debug("Broker connection failed: %s", e)
_retry_connection = True
finally:
self._stopped.set()
if _retry_connection:
LOG.debug(
"Sleeping for %s seconds, then retrying "
"connection",
self._sleep_time
)
time.sleep(self._sleep_time)
self._sleep_time = min(
def __check_for_rabbitmq_availability(self):
"""
Check to see if the RabbitMQ server is available to run commands against.
:return: True if the RabbitMQ server is available to run commands against, False otherwise.
"""
try:
connection = amqp.connection.Connection(
host="%s:%s" % (config.celery_host, config.celery_port),
userid=config.celery_user,
password=config.celery_password,
virtual_host=config.celery_virtual_host,
)
connection.close()
return True
except Exception as e:
if e not in amqp.exceptions.ERROR_MAP.values():
raise e
return False