Skip to content

Commit

Permalink
Update tornado to 6.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh5 committed Aug 31, 2024
1 parent 94e2532 commit 4aa4559
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 36 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Required
schedule==1.2.2
tornado==6.2
tornado==6.3.3
marshmallow~=3.22
peewee>=3.14.4
peewee_migrate==1.6.1
Expand Down
46 changes: 22 additions & 24 deletions unmanic/libs/uiserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,18 @@
OR OTHER DEALINGS IN THE SOFTWARE.
"""

import asyncio
import os
import socket
import threading
import asyncio
import logging
from queue import Queue

from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.platform.asyncio import AnyThreadEventLoopPolicy
from tornado.routing import PathMatches
from tornado.template import Loader
from tornado.web import Application, StaticFileHandler, RedirectHandler
import tornado.httpserver
import tornado.ioloop
import tornado.routing
import tornado.template
import tornado.web

from unmanic import config
from unmanic.libs import common
Expand All @@ -51,7 +49,7 @@

public_directory = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "webserver", "public"))
tornado_settings = {
'template_loader': Loader(public_directory),
'template_loader': tornado.template.Loader(public_directory),
'static_css': os.path.join(public_directory, "css"),
'static_fonts': os.path.join(public_directory, "fonts"),
'static_icons': os.path.join(public_directory, "icons"),
Expand Down Expand Up @@ -229,6 +227,7 @@ def stop(self):
self.started = False
if self.io_loop:
self.io_loop.add_callback(self.io_loop.stop)
self.io_loop.close(True)

def set_logging(self):
if self.config and self.config.get_log_path():
Expand Down Expand Up @@ -276,7 +275,7 @@ def update_tornado_settings(self):
tornado_settings['serve_traceback'] = True

def run(self):
asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy())
asyncio.set_event_loop(asyncio.new_event_loop())
self.started = True

# Configure tornado server based on config
Expand All @@ -288,7 +287,7 @@ def run(self):
# TODO: add support for HTTPS

# Web Server
self.server = HTTPServer(
self.server = tornado.httpserver.HTTPServer(
self.app,
ssl_options=None,
)
Expand All @@ -300,19 +299,18 @@ def run(self):
level="warning")
raise SystemExit

self.io_loop = IOLoop().current()
self.io_loop = tornado.ioloop.IOLoop.current()
self.io_loop.start()
self.io_loop.close(True)

self._log("Leaving UIServer loop...")

def make_web_app(self):
# Start with web application routes
from unmanic.webserver.websocket import UnmanicWebsocketHandler
app = Application([
app = tornado.web.Application([
(r"/unmanic/websocket", UnmanicWebsocketHandler),
(r"/unmanic/downloads/(.*)", DownloadsHandler),
(r"/(.*)", RedirectHandler, dict(
(r"/(.*)", tornado.web.RedirectHandler, dict(
url="/unmanic/ui/dashboard/"
)),
], **tornado_settings)
Expand All @@ -321,31 +319,31 @@ def make_web_app(self):
from unmanic.webserver.api_request_router import APIRequestRouter
app.add_handlers(r'.*', [
(
PathMatches(r"/unmanic/api/.*"),
tornado.routing.PathMatches(r"/unmanic/api/.*"),
APIRequestRouter(app)
),
])

# Add frontend routes
from unmanic.webserver.main import MainUIRequestHandler
app.add_handlers(r'.*', [
(r"/unmanic/css/(.*)", StaticFileHandler, dict(
(r"/unmanic/css/(.*)", tornado.web.StaticFileHandler, dict(
path=tornado_settings['static_css']
)),
(r"/unmanic/fonts/(.*)", StaticFileHandler, dict(
(r"/unmanic/fonts/(.*)", tornado.web.StaticFileHandler, dict(
path=tornado_settings['static_fonts']
)),
(r"/unmanic/icons/(.*)", StaticFileHandler, dict(
(r"/unmanic/icons/(.*)", tornado.web.StaticFileHandler, dict(
path=tornado_settings['static_icons']
)),
(r"/unmanic/img/(.*)", StaticFileHandler, dict(
(r"/unmanic/img/(.*)", tornado.web.StaticFileHandler, dict(
path=tornado_settings['static_img']
)),
(r"/unmanic/js/(.*)", StaticFileHandler, dict(
(r"/unmanic/js/(.*)", tornado.web.StaticFileHandler, dict(
path=tornado_settings['static_js']
)),
(
PathMatches(r"/unmanic/ui/(.*)"),
tornado.routing.PathMatches(r"/unmanic/ui/(.*)"),
MainUIRequestHandler,
),
])
Expand All @@ -356,11 +354,11 @@ def make_web_app(self):
from unmanic.webserver.plugins import PluginAPIRequestHandler
app.add_handlers(r'.*', [
(
PathMatches(r"/unmanic/panel/[^/]+(/(?!static/|assets$).*)?$"),
tornado.routing.PathMatches(r"/unmanic/panel/[^/]+(/(?!static/|assets$).*)?$"),
DataPanelRequestHandler
),
(
PathMatches(r"/unmanic/plugin_api/[^/]+(/(?!static/|assets$).*)?$"),
tornado.routing.PathMatches(r"/unmanic/plugin_api/[^/]+(/(?!static/|assets$).*)?$"),
PluginAPIRequestHandler
),
(r"/unmanic/panel/.*/static/(.*)", PluginStaticFileHandler, dict(
Expand Down
11 changes: 5 additions & 6 deletions unmanic/webserver/api_v2/base_api_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def handle_method_not_allowed(self):
self.set_status(self.STATUS_ERROR_METHOD_NOT_ALLOWED)
self.finish(response)

def action_route(self):
async def action_route(self):
"""
Determine the handler method for the route.
Execute that handler method.
Expand Down Expand Up @@ -255,7 +255,6 @@ def action_route(self):
getattr(self, route.get("call_method"))()
return

# If we got this far, then the URI does not match any of our configured routes.
if matched_route_with_unsupported_method:
tornado.log.app_log.warning("Method not allowed for API route: {}".format(self.request.uri), exc_info=True)
self.handle_method_not_allowed()
Expand All @@ -270,7 +269,7 @@ async def delete(self, path):
:param path:
:return:
"""
await IOLoop.current().run_in_executor(None, self.action_route)
await self.action_route()

async def get(self, path):
"""
Expand All @@ -279,7 +278,7 @@ async def get(self, path):
:param path:
:return:
"""
await IOLoop.current().run_in_executor(None, self.action_route)
await self.action_route()

async def post(self, path):
"""
Expand All @@ -288,7 +287,7 @@ async def post(self, path):
:param path:
:return:
"""
await IOLoop.current().run_in_executor(None, self.action_route)
await self.action_route()

async def put(self, path):
"""
Expand All @@ -297,4 +296,4 @@ async def put(self, path):
:param path:
:return:
"""
await IOLoop.current().run_in_executor(None, self.action_route)
await self.action_route()
9 changes: 4 additions & 5 deletions unmanic/webserver/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@
"""
import json
import queue
import time
import uuid

import tornado.web
import tornado.locks
import tornado.ioloop
import tornado.websocket
from tornado import gen, log
from tornado import gen

from unmanic import config
from unmanic.libs import common, history, session
from unmanic.libs import common, session
from unmanic.libs.uiserver import UnmanicDataQueues, UnmanicRunningTreads
from unmanic.webserver.helpers import completed_tasks, pending_tasks

Expand All @@ -65,7 +64,7 @@ def __init__(self, *args, **kwargs):
self.data_queues = udq.get_unmanic_data_queues()
self.foreman = urt.get_unmanic_running_thread('foreman')
self.session = session.Session()
super(UnmanicWebsocketHandler, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def open(self):
tornado.log.app_log.warning('WS Opened', exc_info=True)
Expand Down Expand Up @@ -359,7 +358,7 @@ async def async_completed_tasks_info(self):
task_list = completed_tasks.prepare_filtered_completed_tasks(params)

for task_result in task_list.get('results', []):
# Set human readable time
# Set human-readable time
if (int(task_result['finish_time']) + 60) > int(time.time()):
human_readable_time = 'Just Now'
else:
Expand Down

0 comments on commit 4aa4559

Please sign in to comment.