Commit 830f7e4b authored by David Huss's avatar David Huss 💬
Browse files

Add Request timeout, handle unreachable endpoints

parent 3e2c0e71
......@@ -41,14 +41,13 @@ def request_meetings(secret: Secret, bbb_url: Url, user_config_path: str) -> Xml
url = "{}/api/{}?checksum={}".format(bbb_url, call_name, checksum)
try:
r = requests.get(url)
r = requests.get(url, timeout=3)
except requests.exceptions.Timeout as e:
# Offline Server!
return XmlDictConfig({"meetings":None})
except:
click.echo("{} The URL \"{}\" is unreachable.\n Check your network connection, and the URL and Secret of the endpoint.".format(click.style('Error:', fg='red', bold=True), url))
print()
time.sleep(1)
if click.confirm(click.style('Do you want to open the config file at {} with your default editor?'.format(user_config_path), fg="yellow"), abort=True):
click.edit(filename=user_config_path)
exit()
# Offline Server!
return XmlDictConfig({"meetings":None})
try:
root = ElementTree.XML(r.text)
......@@ -68,12 +67,16 @@ def request_meetings(secret: Secret, bbb_url: Url, user_config_path: str) -> Xml
return xmldict
def get_meetings(secret: Secret, bbb_url: Url, user_config_path: str) -> Iterable[XmlDictConfig]:
"""
Request meetings and return a list of them. Sorted by biggest first
"""
meetings = []
d = request_meetings(secret, bbb_url, user_config_path)
try:
d = request_meetings(secret, bbb_url, user_config_path)
except:
return ["unreachable"]
if d["meetings"] is None:
return []
......@@ -137,6 +140,10 @@ def list_meetings(config: Config, leaderboards: bool, n: int, participants: bool
print("="*click.get_terminal_size()[0])
print()
if meeting[0] == "unreachable":
printing.print_header(endpoint.name, "No connection..", fancy)
continue
# If there are no meetings, skip to next endpoint
if len(meeting) == 0:
if show_meetings:
......@@ -226,6 +233,10 @@ def meetings_twolines(config: Config, watch: int, fancy: bool):
print(lines)
continue
if meeting[0] == "unreachable":
printing.print_header(endpoint.name, "No connection..", fancy)
continue
n_running = len(meeting)
n_recording = len([m for m in meeting if m["recording"] == "true"])
n_participants = sum([int(m["participantCount"]) for m in meeting])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment