Commit c03392ec authored by Federico Sismondi's avatar Federico Sismondi

added _api_version field in SessionLog messages, also adopter a let-it-crash...

added _api_version field in SessionLog messages, also adopter a let-it-crash approach when sending or receiving messages on the bus regarding amqp connection, channels and broken pipes
parent 568dc306
Pipeline #1956 passed with stage
in 0 seconds
......@@ -10,7 +10,7 @@ try:
except:
from .messages import *
VERSION = '0.0.9'
VERSION = '0.0.10'
AMQP_EXCHANGE = 'amq.topic'
MAX_LOG_LINE_LENGTH = 120
......@@ -168,13 +168,9 @@ def publish_message(connection, message):
Creates temporary channel on it's own
Connection must be a pika.BlockingConnection
"""
channel = None
try:
channel = connection.channel()
properties = pika.BasicProperties(**message.get_properties())
channel.basic_publish(
exchange=AMQP_EXCHANGE,
routing_key=message.routing_key,
......@@ -182,7 +178,6 @@ def publish_message(connection, message):
body=message.to_json(),
)
finally:
if channel and channel.is_open:
channel.close()
......@@ -204,9 +199,8 @@ def amqp_request(connection, request_message, component_id, retries=10):
time_between_requests = 0.5
channel = None
try:
response = None
reply_queue_name = 'amqp_rpc_%s@%s' % (str(uuid.uuid4())[:8], component_id)
channel = connection.channel()
......@@ -240,13 +234,12 @@ def amqp_request(connection, request_message, component_id, retries=10):
retries_left -= 1
if retries_left > 0:
body_dict = json.loads(body.decode('utf-8'), object_pairs_hook=OrderedDict)
response = MsgReply(request_message, **body_dict)
else:
# clean up
channel.queue_delete(reply_queue_name)
channel.close()
raise AmqpSynchCallTimeoutError(
"Response timeout! rkey: %s , request type: %s" % (
request_message.routing_key,
......@@ -254,14 +247,13 @@ def amqp_request(connection, request_message, component_id, retries=10):
)
)
return response
finally:
if channel and channel.is_open:
# clean up
channel.queue_delete(reply_queue_name)
channel.close()
return response
if __name__ == '__main__':
......
......@@ -40,6 +40,7 @@ except ImportError:
pass
VERSION = '0.0.8'
API_VERSION = '1.0.8'
# defaults vars
AMQP_URL = 'amqp://guest:guest@localhost'
......@@ -172,6 +173,7 @@ class JsonFormatter(logging.Formatter):
try:
log_record = OrderedDict()
log_record['component'] = record.name
log_record['_api_version'] = API_VERSION
except NameError:
log_record = {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment