Skip to content
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

Merged
merged 3 commits into from Dec 13, 2017
Merged

LB-196: Remove duplication of RabbitMQ connection code #310

merged 3 commits into from Dec 13, 2017

Conversation

ghost
Copy link

@ghost ghost commented Dec 2, 2017

Summary

  • This is a…
    • Bug fix
    • Feature addition
    • Refactoring
    • Minor / simple change (like a typo)
    • Other
  • Describe this change in 1-2 sentences:

This change extracts the common RabbitMQ connection code into one function in utils.py.

Problem

Solution

connect_to_rabbitmq in utils.py tries repeatedly until it's able to connect to RabbitMQ and then returns the Connection object.

Action

@paramsingh

@ghost
Copy link
Author

ghost commented Dec 2, 2017

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 tarfile throwing a ReadError when import_listens_dump tries to open a particular dump_location, but I do not know what location this is referring to. It doesn't really appear to be a Travis problem since I ran ./test.sh locally just now and it failed in the same way.

@ghost
Copy link
Author

ghost commented Dec 2, 2017

@paramsingh Out of curiosity, I ran ./test.sh two minutes ago on my local copy of this branch, without any local directory changes, no new commits, nothing. Magically, it worked. So I thought the issue kind of resolved itself here, or at the very least I could make the Travis build pass for now. I made a really minor change to a docstring so I would have something I could run git commit --amend on. I force-pushed, and the Travis build fails, once again in the same way.

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.

Copy link
Collaborator

@paramsingh paramsingh left a 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
Copy link
Collaborator

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.

@paramsingh
Copy link
Collaborator

The test failures seem unrelated, I'll take a look when I get the chance.

@paramsingh
Copy link
Collaborator

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. 🙄

@ghost
Copy link
Author

ghost commented Dec 4, 2017

@parasingh I have a few questions related to the task. If I create a new class ListenWriter and inherit from it in BQ listener and Influx listener, do you want the whole util.connect_to_rabbitmq method to go there?

In this case, what should be done for webserver/rabbitmq_connection.py, which only has a method called init_rabbitmq_connection?

Do you want to move any other methods to this new base class?

Only very basic abstraction and commonality is
included in ListenWriter.
@ghost
Copy link
Author

ghost commented Dec 4, 2017

Made a few basic changes - a new ListenWriter class, with some functionality I was able to identify as common, is the base class of BigQueryWriter and InfluxWriter classes. There's some more stuff left, like the initial code in the start methods, but I wasn't able to extract any semantic meaning out of those sections myself - I would love some suggestions on it.

credentials=credentials
)
connection_config = {
"username": app.config['RABBITMQ_USERNAME'],
Copy link
Collaborator

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer ' :)

Copy link
Collaborator

@paramsingh paramsingh left a 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 ===================================
``

@ghost
Copy link
Author

ghost commented Dec 4, 2017

@paramsingh Fixed. Actually I didn't realize integration_test.sh existed 😥 But anywho, the failures were caused by the ListenWriter not being imported properly, and me not changing config to self.config in InfluxWriter. I did it in BQWriter, but not Influx 🤦‍♀️ .

EDIT: YES! Travis is a ✅

Fixed quote problem as well!

Plus cosmetic fix - consistency with quotes in strings.
@mayhem mayhem merged commit ad86a19 into metabrainz:master Dec 13, 2017
@ghost ghost deleted the rabbitmq-duplication branch December 13, 2017 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants