Skip to content

Commit

Permalink
Don't crash if nextSequenceToken is missing. Fixes #134
Browse files Browse the repository at this point in the history
  • Loading branch information
kislyuk committed Jan 11, 2021
1 parent 23ae223 commit a3216c6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion watchtower/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ def _submit_batch(self, batch, stream_name, max_retries=5):
# response can be None only when all retries have been exhausted
if response is None or "rejectedLogEventsInfo" in response:
warnings.warn("Failed to deliver logs: {}".format(response), WatchtowerWarning)
else:
elif "nextSequenceToken" in response:
# According to https://github.com/kislyuk/watchtower/issues/134, nextSequenceToken may sometimes be absent
# from the response
self.sequence_tokens[stream_name] = response["nextSequenceToken"]

def emit(self, message):
Expand Down Expand Up @@ -282,6 +284,10 @@ def truncate(_msg2):
my_queue.task_done()

def flush(self):
"""
Send any queued messages to CloudWatch. This method does nothing if ``use_queues`` is set to False.
"""
# fixme: don't add filter if it's already installed
self.addFilter(_boto_filter)
if self.shutting_down:
return
Expand All @@ -291,6 +297,11 @@ def flush(self):
q.join()

def close(self):
"""
Send any queued messages to CloudWatch and prevent further processing of messages.
This method does nothing if ``use_queues`` is set to False.
"""
# fixme: don't add filter if it's already installed
self.addFilter(_boto_filter)
# Avoid waiting on the queue again when the close called twice.
# Otherwise the second call, as no thread is running, it will hang
Expand Down

0 comments on commit a3216c6

Please sign in to comment.