Commit 117ee1f0 authored by echel0n's avatar echel0n
Browse files

Merge branch 'release/10.0.21'

parents 2e8c2f38 6c82d5b5
......@@ -2,8 +2,12 @@
 
All notable changes to this project will be documented in this file. Dates are displayed in UTC.
 
#### [10.0.21](https://git.sickrage.ca/SiCKRAGE/sickrage/compare/10.0.20...10.0.21)
#### [10.0.20](https://git.sickrage.ca/SiCKRAGE/sickrage/compare/10.0.19...10.0.20)
 
> 31 July 2021
#### [10.0.19](https://git.sickrage.ca/SiCKRAGE/sickrage/compare/10.0.18...10.0.19)
 
> 30 July 2021
......
{
"name": "sickrage",
"version": "10.0.20",
"version": "10.0.21",
"private": true,
"repository": {
"type": "git",
......
[bumpversion]
current_version = 10.0.20
current_version = 10.0.21
commit = False
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<release>[a-z]+)(?P<dev>\d+))?
......
......@@ -19,7 +19,7 @@
# along with SiCKRAGE. If not, see <http://www.gnu.org/licenses/>.
# ##############################################################################
__version__ = "10.0.20"
__version__ = "10.0.21"
__install_type__ = ""
import argparse
......
This diff is collapsed.
......@@ -18,7 +18,6 @@
# You should have received a copy of the GNU General Public License
# along with SiCKRAGE. If not, see <http://www.gnu.org/licenses/>.
# ##############################################################################
import asyncio
import datetime
import locale
import logging
......@@ -43,8 +42,7 @@ from apscheduler.triggers.interval import IntervalTrigger
from dateutil import tz
from fake_useragent import UserAgent
from sentry_sdk.integrations.logging import LoggingIntegration
from tornado.ioloop import IOLoop
from tornado.platform.asyncio import AnyThreadEventLoopPolicy
from tornado.ioloop import IOLoop, PeriodicCallback
import sickrage
from sickrage.core.amqp import AMQPClient
......@@ -82,6 +80,7 @@ from sickrage.core.updaters.tz_updater import TimeZoneUpdater
from sickrage.core.upnp import UPNPClient
from sickrage.core.version_updater import VersionUpdater, SourceUpdateManager
from sickrage.core.webserver import WebServer
from sickrage.core.websocket import check_web_socket_queue
from sickrage.metadata_providers import MetadataProviders
from sickrage.notification_providers import NotificationProviders
from sickrage.search_providers import SearchProviders
......@@ -237,9 +236,6 @@ class Core(object):
# thread name
threading.currentThread().setName('CORE')
# event loop policy that allows loop creation on any thread.
asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy())
# init sentry
self.init_sentry()
......@@ -569,7 +565,10 @@ class Core(object):
IOLoop.current().add_callback(self.launch_browser)
# shutdown trigger
IOLoop.current().add_callback(self.shutdown_trigger)
PeriodicCallback(self.shutdown_trigger, 5 * 1000).start()
# watch websocket message queue
PeriodicCallback(check_web_socket_queue, 100).start()
# start ioloop
IOLoop.current().start()
......@@ -697,7 +696,5 @@ class Core(object):
self.started = False
def shutdown_trigger(self):
if self.started:
IOLoop.current().add_timeout(datetime.timedelta(seconds=5), self.shutdown_trigger)
else:
if not self.started:
IOLoop.current().stop()
......@@ -2,27 +2,32 @@ import json
from queue import Queue
from jose import JWTError, ExpiredSignatureError
from tornado.ioloop import IOLoop
from tornado.websocket import WebSocketHandler
import sickrage
clients = set()
message_queue = Queue()
def check_web_socket_queue():
if not WebSocketUIHandler.message_queue.empty():
message = WebSocketUIHandler.message_queue.get()
WebSocketUIHandler.broadcast(message)
class WebSocketUIHandler(WebSocketHandler):
"""WebSocket handler to send and receive data to and from a web client."""
clients = set()
message_queue = Queue()
def check_origin(self, origin):
"""Allow alternate origins."""
return True
def open(self, *args, **kwargs):
"""Client connected to the WebSocket."""
clients.add(self)
while not message_queue.empty():
self.write_message(message_queue.get())
WebSocketUIHandler.clients.add(self)
# while not WebSocketUIHandler.message_queue.empty():
# self.write_message(WebSocketUIHandler.message_queue.get())
def on_message(self, message):
"""Received a message from the client."""
......@@ -34,13 +39,13 @@ class WebSocketUIHandler(WebSocketHandler):
try:
decoded_token = sickrage.app.auth_server.decode_token(auth_token, certs)
if sickrage.app.config.user.sub_id != decoded_token.get('sub'):
clients.remove(self)
WebSocketUIHandler.clients.remove(self)
self.close(401, 'Not Authorized')
except ExpiredSignatureError:
clients.remove(self)
WebSocketUIHandler.clients.remove(self)
self.close(401, 'Token expired')
except JWTError as e:
clients.remove(self)
WebSocketUIHandler.clients.remove(self)
self.close(401, f'Improper JWT token supplied, {e!r}')
else:
sickrage.app.log.debug('WebSocket received message from {}: {}'.format(self.request.remote_ip, message))
......@@ -51,7 +56,12 @@ class WebSocketUIHandler(WebSocketHandler):
def on_close(self):
"""Client disconnected from the WebSocket."""
clients.remove(self)
WebSocketUIHandler.clients.remove(self)
@classmethod
def broadcast(cls, msg):
for client in cls.clients:
client.write_message(json.dumps(msg))
def __repr__(self):
"""Client representation."""
......@@ -84,10 +94,4 @@ class WebSocketMessage(object):
def push(self):
"""Push the message to all connected WebSocket clients."""
# message_queue.put(self.json())
for client in clients.copy():
try:
message = self.json()
IOLoop.current().run_in_executor(None, client.write_message, message)
except AssertionError:
continue
WebSocketUIHandler.message_queue.put(self.json())
10.0.20
\ No newline at end of file
10.0.21
\ No newline at end of file
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