Configure a timeout on SenderBase. Helps with Issue-16 (#34)
This commit is contained in:
Родитель
097b575de9
Коммит
0e5b9223ab
|
@ -25,6 +25,7 @@ class SenderBase(object):
|
|||
self._service_endpoint_uri = service_endpoint_uri
|
||||
self._queue = None
|
||||
self._send_buffer_size = 100
|
||||
self._timeout = 10
|
||||
|
||||
@property
|
||||
def service_endpoint_uri(self):
|
||||
|
@ -63,6 +64,21 @@ class SenderBase(object):
|
|||
"""
|
||||
return self._queue
|
||||
|
||||
@property
|
||||
def send_timeout(self):
|
||||
"""Time in seconds that the sender should wait before giving up."""
|
||||
return self._timeout
|
||||
|
||||
@send_timeout.setter
|
||||
def send_timeout(self, seconds):
|
||||
"""Configures the timeout in seconds the sender waits for a response for the server.
|
||||
|
||||
Args:
|
||||
seconds(float). Timeout in seconds.
|
||||
"""
|
||||
|
||||
self._send_buffer_size = seconds
|
||||
|
||||
@queue.setter
|
||||
def queue(self, value):
|
||||
"""The queue that this sender is draining. While :class:`SenderBase` doesn't implement any means of doing
|
||||
|
@ -115,7 +131,7 @@ class SenderBase(object):
|
|||
|
||||
request = HTTPClient.Request(self._service_endpoint_uri, bytearray(request_payload, 'utf-8'), { 'Accept': 'application/json', 'Content-Type' : 'application/json; charset=utf-8' })
|
||||
try:
|
||||
response = HTTPClient.urlopen(request)
|
||||
response = HTTPClient.urlopen(request, timeout=self._timeout)
|
||||
status_code = response.getcode()
|
||||
if 200 <= status_code < 300:
|
||||
return
|
||||
|
|
Загрузка…
Ссылка в новой задаче