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

Removed sseclient dependency + major enhancements on event_stream() #143

Merged
merged 17 commits into from Aug 29, 2016

Conversation

migueleliasweb
Copy link
Contributor

No description provided.

while servers and messages is None:
server = servers.pop(0)
def _do_sse_request(self, path):
for server in list(self.servers):
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a change in behaviour. Previously, we were looping so long as we didn't have a response, but now we're doing the request on each server, irrespective of whether the request was successful. Please change it back :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okie dokie !

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the delay. I had so solve some personal problems on the last couple of days but I'm still going to fix this !

@solarkennedy
Copy link
Contributor

Can you address the failing itests?
https://travis-ci.org/thefactory/marathon-python/jobs/154326294#L3594

@migueleliasweb
Copy link
Contributor Author

Working on it !

On Aug 23, 2016 17:32, "Kyle Anderson" notifications@github.com wrote:

Can you address the failing itests?
https://travis-ci.org/thefactory/marathon-python/jobs/154326294#L3594


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#143 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABiKFJYEMKhUoDiQMsbVdCRd0Edb-9cHks5qi1jogaJpZM4JqPuI
.

except Exception as e:
marathon.log.error('Error while calling %s: %s', url, e.message)

if messages is None:
raise MarathonError('No remaining Marathon servers to try')
if response.ok:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Rob-Johnson This should fix, right ?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, this is fine.

@solarkennedy
Copy link
Contributor

I do like the reduction in dependencies, but do we not need any SSE specific code that came with that client?

We at Yelp don't use this feature. I'm only slightly more hesitant to merge it.

@nuclon do you have any opinion?

@migueleliasweb
Copy link
Contributor Author

@solarkennedy If you want I can leave the sseclient dependency for now, not a problem but I searched the codebase and only found use on the _do_sse_request.

See the previous code:

def _do_sse_request(self, path, params=None, data=None):
        from sseclient import SSEClient

        headers = {'Accept': 'text/event-stream'}
        messages = None
        servers = list(self.servers)
        while servers and messages is None:
            server = servers.pop(0)
            url = ''.join([server.rstrip('/'), path])
            try:
                messages = SSEClient(url, params=params, data=data, headers=headers,
                                     auth=self.auth)
            except Exception as e:
                marathon.log.error('Error while calling %s: %s', url, e.message)

        if messages is None:
            raise MarathonError('No remaining Marathon servers to try')

        return messages

The sseclient is only imported on this very method.

I'm not pushing but I think this is kinda safe.

Feel free to ask any question.

@nuclon
Copy link

nuclon commented Aug 27, 2016

@solarkennedy I've made small pull request to sseclient recently and it fixes that weird CPU problem.
https://bitbucket.org/btubbs/sseclient/pull-requests/9/response-readline/diff
and now everything works well. (we're using this feature in our company)

Of course it's your call to decide - remove the dependency or not.

@migueleliasweb
Copy link
Contributor Author

@nuclon Instead of iterating char by char you made the iteration by line, am I right ? If so, that should do.

def __next__(self):
         while not self._event_complete():
             try:
-                nextchar = next(self.resp_iterator)
-                self.buf += nextchar
-            except (StopIteration, requests.RequestException):
+                nextline = self.resp_file.readline()
+                if not nextline:
+                    raise EOFError()
+                self.buf += nextline
+            except (StopIteration, requests.RequestException, EOFError) as e:
                 time.sleep(self.retry / 1000.0)
                 self._connect()

I would like (as a bonus of solving this problem) removing an external dependency but the truth is both codes would solve the issue with huge json responses from marathon.

@solarkennedy Feel free to chose any. I just like to solve this problem asap. I have a running code on production that might snap at any time =/

@solarkennedy solarkennedy merged commit 7765027 into thefactory:master Aug 29, 2016
@solarkennedy
Copy link
Contributor

I agree that removing the dep is good too. I'll make a new release to include this change.

@migueleliasweb
Copy link
Contributor Author

Hooray !

@dmsimard
Copy link

seeclient is still marked in setup.py as a dependency: https://github.com/thefactory/marathon-python/blob/master/setup.py#L16

@migueleliasweb
Copy link
Contributor Author

I saw that after the merge was made. I ll make another pr to remove it from
the setup.py.

On Oct 17, 2016 11:19, "David Moreau Simard" notifications@github.com
wrote:

seeclient is still marked in setup.py as a dependency:
https://github.com/thefactory/marathon-python/blob/master/setup.py#L16


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#143 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABiKFKb28DfNnaHcs3fv7VQTsMWw6c1uks5q03XbgaJpZM4JqPuI
.

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.

None yet

5 participants