From 798aa8ec3d6889faf938cc3316d76a7ef2c6ac41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Gl=C3=BCpker?= Date: Fri, 30 Mar 2018 12:58:27 +0200 Subject: Query servers in parallel and check for updates --- main.py | 28 ++++++++++++++++++++++++++-- static/style.css | 5 +++++ templates/server_html.jinja | 3 +++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 2a1f51b..823b31f 100755 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ from flask import Flask, flash, redirect, render_template, request, session, url # from wsgiref.util import setup_testing_defaults from collections import OrderedDict +from concurrent.futures import ThreadPoolExecutor import json import os @@ -172,8 +173,31 @@ def premades(): def server(): with open(os.path.join(CONFIG, 'server.json'), 'rt') as config: servers = json.load(config) - for name, server in servers.items(): - server['data'] = QueryServer.QueryServer(server['ip'], server['port'], server['gameid']) + + executor = ThreadPoolExecutor(max_workers=10) + serverdata_ = dict() + for _, serverdata in servers.items(): + name = "{0}{1:d}{2:d}".format(serverdata['ip'], serverdata['port'], serverdata['gameid']) + serverdata_[name] = executor.submit( + QueryServer.QueryServer, + serverdata['ip'], + serverdata['port'], + serverdata['gameid'] + ) + + for _, serverdata in servers.items(): + name = "{0}{1:d}{2:d}".format(serverdata['ip'], serverdata['port'], serverdata['gameid']) + serverdata['data'] = serverdata_[name].result() + serverdata_['u' + name] = executor.submit( + steam.getGameUpdateState, + serverdata['data']['gameid'], + serverdata['data']['gameversion'] + ) + + for _, serverdata in servers.items(): + name = "{0}{1:d}{2:d}".format(serverdata['ip'], serverdata['port'], serverdata['gameid']) + serverdata['update'] = serverdata_['u' + name].result() + return render_template('server_html.jinja', servers=servers, display_time = display_time diff --git a/static/style.css b/static/style.css index d27276f..9544769 100644 --- a/static/style.css +++ b/static/style.css @@ -183,6 +183,11 @@ div.serverdata { /* overflow: scroll; */ } +span.updatemessage { + color: red; + font-weight: bold; +} + a.servername { color: lightblue; font-weight: bold; diff --git a/templates/server_html.jinja b/templates/server_html.jinja index 5e38b0a..9702300 100644 --- a/templates/server_html.jinja +++ b/templates/server_html.jinja @@ -28,6 +28,9 @@
  • {{ info['data']['map'] }}
  • {{ info['data']['players'] }} / {{ info['data']['playersmax'] }}
  • + {% if info['update']['success'] %} + {{ info['update']['message'] }} + {% endif %} {% if info['data']['players'] %} -- cgit v1.2.3