New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LB-196: Remove duplication of RabbitMQ connection code #310
Conversation
I am not sure where this Travis error is coming from. It appeared in #308 as well, seemingly randomly. It failed on one commit, and when I committed again without even touching the code, it passed. The error is |
@paramsingh Out of curiosity, I ran It seems to be a problem with how the Travis machine is configured or started, or something because I can't seem a pattern here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding an extra function to utils, creating a new ListenWriter class from which we inherit methods in BQ writer and Influx writer might be a good idea. We could then try to move other methods out to that class as well.
@@ -14,6 +14,8 @@ | |||
from listenbrainz.utils import escape, get_measurement_name, get_escaped_measurement_name, \ | |||
get_influx_query_timestamp, convert_to_unix_timestamp, \ | |||
convert_timestamp_to_influx_row_format | |||
# Doing this so as not to confuse the method names | |||
from listenbrainz.utils import connect_to_rabbitmq as utils_connect_to_rabbitmq |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just do an import listenbrainz.utils as utils
here too.
The test failures seem unrelated, I'll take a look when I get the chance. |
I know i said adding to the utils file was what I said in the task but the class seems like a better idea now. 🙄 |
@parasingh I have a few questions related to the task. If I create a new class In this case, what should be done for Do you want to move any other methods to this new base class? |
Only very basic abstraction and commonality is included in ListenWriter.
Made a few basic changes - a new |
credentials=credentials | ||
) | ||
connection_config = { | ||
"username": app.config['RABBITMQ_USERNAME'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistency here between "
and '
would be appreciated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer '
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind taking a look at why the integration tests fail?
The tarfile test is unrelated, but these failures seem to be caused due to the changes made in the code here.
============================= test session starts ==============================
platform linux -- Python 3.6.1, pytest-2.9.1, py-1.5.2, pluggy-0.3.1
rootdir: /code/listenbrainz, inifile: pytest.ini
plugins: cov-2.2.1
collected 39 items
listenbrainz/tests/integration/test_api.py FF.................
listenbrainz/tests/integration/test_api_compat_deprecated.py .........F....
listenbrainz/tests/integration/test_influx_writer.py FFFFF
listenbrainz/tests/integration/test_profile_views.py F
=================================== FAILURES ===================================
``
@paramsingh Fixed. Actually I didn't realize EDIT: YES! Travis is a ✅ Fixed quote problem as well! |
Plus cosmetic fix - consistency with quotes in strings.
Summary
This change extracts the common RabbitMQ connection code into one function in
utils.py
.Problem
Solution
connect_to_rabbitmq
inutils.py
tries repeatedly until it's able to connect to RabbitMQ and then returns theConnection
object.Action
@paramsingh