Added timeout for requests
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
448acd4dd0
commit
d3656b543f
@ -6,6 +6,7 @@ Communicator module
|
||||
|
||||
import logging
|
||||
import requests
|
||||
import requests.exceptions
|
||||
|
||||
__author__ = "@tormakris"
|
||||
__copyright__ = "Copyright 2020, GoldenPogácsa Team"
|
||||
@ -38,8 +39,11 @@ class Communicator:
|
||||
"""
|
||||
currentconsumer=self.currenctconsumer
|
||||
LOGGER.info(f"Sending message to {currentconsumer}")
|
||||
postresponse=requests.post(f'http://{currentconsumer}/log', json={'uuid': self.uuid, 'message': message})
|
||||
LOGGER.debug(f"Message status code is:{postresponse.status_code}")
|
||||
try:
|
||||
postresponse=requests.post(f'http://{currentconsumer}/log', json={'uuid': self.uuid, 'message': message}, timeout=5)
|
||||
LOGGER.debug(f"Message status code is:{postresponse.status_code}")
|
||||
except (requests.exceptions.Timeout, requests.exceptions.ConnectionError) as e:
|
||||
LOGGER.exception(e) # Fun fact: ez azt jelenti, hogy elveszett az üzenet... ide valami retry kellene inkább más consumerek felé...
|
||||
|
||||
def discoveravailableconsumers(self) -> list:
|
||||
"""Get the list of available consumer from the current primary consumer. Logs the received list.
|
||||
@ -48,7 +52,7 @@ class Communicator:
|
||||
"""
|
||||
try:
|
||||
currentconsumer = self.currenctconsumer
|
||||
response = requests.get(f'http://{currentconsumer}/consumers')
|
||||
response = requests.get(f'http://{currentconsumer}/consumers', timeout=5)
|
||||
json = response.json()
|
||||
LOGGER.info(f"List of currently available consumers: {json}")
|
||||
return json
|
||||
@ -63,7 +67,7 @@ class Communicator:
|
||||
"""
|
||||
currentconsumer = self.currenctconsumer
|
||||
try:
|
||||
response = requests.get(f'http://{currentconsumer}/consumers')
|
||||
response = requests.get(f'http://{currentconsumer}/consumers', timeout=5)
|
||||
isavailable = response.status_code == 200
|
||||
except Exception as e:
|
||||
LOGGER.exception(e)
|
||||
@ -78,7 +82,7 @@ class Communicator:
|
||||
:return: True if available, False otherwise
|
||||
"""
|
||||
try:
|
||||
response = requests.get(f'http://{consumer}/consumers')
|
||||
response = requests.get(f'http://{consumer}/consumers', timeout=5)
|
||||
isavailable = response.status_code == 200
|
||||
except Exception as e:
|
||||
LOGGER.exception(e)
|
||||
|
Reference in New Issue
Block a user