Skip to content

Commit 1ef8026

Browse files
committedMay 23, 2018
Gracefully handle an empty message queue
Print a nice message instead of a stack trace if the message queue is empty when we try to read from it.
1 parent 99d166b commit 1ef8026

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed
 

‎committelemetry/pulse.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
See https://wiki.mozilla.org/Auto-tools/Projects/Pulse
88
"""
99
import logging
10+
import socket
1011
from contextlib import closing
1112
from functools import partial
1213

@@ -116,10 +117,7 @@ def process_push_message(body, message, no_send=False):
116117

117118

118119
def run_pulse_listener(username, password, timeout, no_send):
119-
"""Run a Pulse message queue listener.
120-
121-
This function does not return.
122-
"""
120+
"""Run a Pulse message queue listener."""
123121
connection = Connection(
124122
hostname='pulse.mozilla.org',
125123
port=5671,
@@ -174,4 +172,9 @@ def run_pulse_listener(username, password, timeout, no_send):
174172
log.info('message acks has been disabled')
175173

176174
log.info('reading messages')
177-
connection.drain_events(timeout=timeout)
175+
try:
176+
connection.drain_events(timeout=timeout)
177+
except socket.timeout:
178+
log.info('message queue is empty, nothing to do')
179+
180+
log.info('done')

0 commit comments

Comments
 (0)
Failed to load comments.