Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Use requests directly, instead of sseclient. #114

Merged
merged 1 commit into from
Mar 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions marathon_lb.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
from tempfile import mkstemp
from textwrap import dedent
from wsgiref.simple_server import make_server
from sseclient import SSEClient
from six.moves.urllib import parse
from itertools import cycle
from common import *
Expand Down Expand Up @@ -650,7 +649,26 @@ def get_event_stream(self):
url = self.host+"/v2/events"
logger.info(
"SSE Active, trying fetch events from from {0}".format(url))
return SSEClient(url, auth=self.__auth)

headers = {
'Cache-Control': 'no-cache',
'Accept': 'text/event-stream'
}

resp = requests.get(url, stream=True,
headers=headers, auth=self.__auth)

class Event(object):
def __init__(self, data):
self.data = data

for line in resp.iter_lines():
if line.strip() != '':
for real_event_data in re.split(r'\r\n',
line.decode('utf-8')):
if real_event_data[:6] == "data: ":
event = Event(data=real_event_data[6:])
yield event

@property
def host(self):
Expand Down Expand Up @@ -1622,10 +1640,10 @@ def process_sse_events(marathon, config_file, groups,
args.ssl_certs)
except:
logger.exception("Caught exception")
logger.error("Reconnecting...")
backoff = backoff * 1.5
if backoff > 300:
backoff = 300
logger.error("Reconnecting in {}s...", backoff)
# Reset the backoff if it's been more than 10 minutes
if time.time() - stream_started > 600:
backoff = 3
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
requests
six
sseclient
python-dateutil