Merge branch 'feature/async-polling' into 'dev'

Made server polls asynchronus, fix for serverjars

See merge request crafty-controller/crafty-commander!115
This commit is contained in:
Quentin 2021-12-17 16:28:32 +00:00
commit d4dbbcac35
2 changed files with 24 additions and 14 deletions

View File

@ -9,7 +9,7 @@ import datetime
import os import os
from tornado import iostream from tornado import iostream
from tornado.ioloop import IOLoop
from app.classes.shared.console import console from app.classes.shared.console import console
from app.classes.shared.main_models import Users, installer from app.classes.shared.main_models import Users, installer
@ -27,8 +27,26 @@ logger = logging.getLogger(__name__)
class PanelHandler(BaseHandler): class PanelHandler(BaseHandler):
# Server fetching, spawned asynchronously
# TODO: Make the related front-end elements update with AJAX
def fetch_server_data(self, page_data):
total_players = 0
for server in page_data['servers']:
total_players += len(self.controller.stats.get_server_players(server['server_data']['server_id']))
page_data['num_players'] = total_players
for s in page_data['servers']:
try:
data = json.loads(s['int_ping_results'])
s['int_ping_results'] = data
except Exception as e:
logger.error("Failed server data for page with error: {} ".format(e))
return page_data
@tornado.web.authenticated @tornado.web.authenticated
def get(self, page): async def get(self, page):
error = bleach.clean(self.get_argument('error', "WTF Error!")) error = bleach.clean(self.get_argument('error', "WTF Error!"))
template = "panel/denied.html" template = "panel/denied.html"
@ -153,17 +171,9 @@ class PanelHandler(BaseHandler):
except: except:
data['stats']['waiting_start'] = False data['stats']['waiting_start'] = False
total_players = 0 page_data['num_players'] = 0
for server in page_data['servers']:
total_players += len(self.controller.stats.get_server_players(server['server_data']['server_id']))
page_data['num_players'] = total_players
for s in page_data['servers']: IOLoop.current().add_callback(self.fetch_server_data, page_data)
try:
data = json.loads(s['int_ping_results'])
s['int_ping_results'] = data
except Exception as e:
logger.error("Failed server data for page with error: {} ".format(e))
template = "panel/dashboard.html" template = "panel/dashboard.html"

View File

@ -81,8 +81,8 @@ class ServerHandler(BaseHandler):
self.redirect("/panel/error?error=Unauthorized access: not a server creator or server limit reached") self.redirect("/panel/error?error=Unauthorized access: not a server creator or server limit reached")
return return
page_data['server_types'] = server_jar_obj.get_serverjar_data_sorted() page_data['server_types'] = server_jar_obj.get_serverjar_data()
page_data['js_server_types'] = json.dumps(server_jar_obj.get_serverjar_data_sorted()) page_data['js_server_types'] = json.dumps(server_jar_obj.get_serverjar_data())
template = "server/wizard.html" template = "server/wizard.html"
self.render( self.render(