Skip to content

Conversation

manugarri
Copy link
Contributor

This PR implements the following changes:

  • Supports json encoded messages
  • Supports uncompressed messages
  • P3 compatible
  • Minor fixes (remove commented code and unused imports)

I set all the default encoding to msgpack and the decompress to True. That should make it compatible with current use cases.

self.decompress_fun = zlib.decompress
def __init__(self, encoding=None, decompress=None, msgformat=None):
if decompress:
import zlib
Copy link
Member

Choose a reason for hiding this comment

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

why lazy import of zlib? It is a standard library.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, i can import it, there is no point in polluting the global namespace unnecesarily but it wouldnt be a big deal.

def get_kafka_msg_samples(msgs=None, fetch_count=0, msgformat='msgpack', compress=True):
if not msgs:
msgs = [('AD12345', "my-body"),
('AD34567', "second my-body"),
Copy link
Member

Choose a reason for hiding this comment

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

Can you separate pylint style fixes and new feature in different commits?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh ok, do you guys dont mind if there are multiple commits per PR? or should i remove it completely and then do another PR?

Copy link
Member

Choose a reason for hiding this comment

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

I don't mind multiple commits per PR. Not needed an extra PR.

def __init__(self, handlers_list, encoding=None, *args, **kwargs):
self._handlers = []
self.processor_handlers = MsgProcessorHandlers(encoding=encoding)
self.processor_handlers = MsgProcessorHandlers(encoding=encoding, *args, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

it is weird that positional arguments *args come after a key argument encoding=. Didn't pylint complain here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, afaik this is perfectly valid. If it goes against SH style guide let me know and I can make it an unnamed argument (i always prefer using names for the shake of documenting but I see your point).

self.__encoding = encoding
self.deserialize_fun = self.set_deserializer(msgformat)

def set_deserializer(self, msg_format):
Copy link
Member

Choose a reason for hiding this comment

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

in the way you are using this method, seems better a name like get_deserializer(). The method doesn't really set anything. Only returns an object than it is set in previous line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, naming is important

for i in range(100, 200):
self.assertTrue('AD%.3d' % i not in msgsdict)

# def test_kafka_scan_resume(self, kafka_consumer_mock, batchsize=100):
Copy link
Member

Choose a reason for hiding this comment

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

please, don't remove this test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah this was an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, now that I see, this whole code block is commented in master. Are you sure you want to keep it in master? Saving code that you might use in the future is not good practice (YAGNI probably), and that is what git history is for.

Copy link
Member

Choose a reason for hiding this comment

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

you are right. I hand't noticed this was commented test.

@manugarri
Copy link
Contributor Author

@kalessin Fixed the changes, and commented on your requests. Let me know if you need anything else. We are using kafka scanners and I'd rather not keep our own fork when this change could benefit everyone instead.

@kalessin kalessin merged commit 8095461 into scrapinghub:master Sep 29, 2017
@kalessin
Copy link
Member

kalessin commented Sep 29, 2017

thanks @manugarri . I merged and updated/tagged version. New version just published into pypi.

@kalessin
Copy link
Member

@manugarri
Copy link
Contributor Author

yaaay! Thanks @kalessin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants