Attaching Tornado ioloop to SystemThread, handling SystemThread errors with JsonRPC structure

This commit is contained in:
James Barnsley
2020-01-17 21:55:12 +13:00
parent 76dc149041
commit 0e15a8745e
7 changed files with 19414 additions and 27434 deletions

View File

@ -155,7 +155,6 @@ class IrisCore(pykka.ThreadingActor):
logger.debug(data)
# Catch invalid recipient
if data['recipient'] not in self.connections:
error = 'Connection "'+data['recipient']+'" not found'

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -100,7 +100,7 @@
// Release details
// These are automatically injected to built HTML
var build = "1578380990";
var build = "1579250766";
var version = "3.44.0";
// Construct the script tag

View File

@ -1,5 +1,5 @@
from threading import Thread
import logging, os, pathlib, subprocess, json
import logging, os, pathlib, subprocess, json, tornado
# import logger
logger = logging.getLogger(__name__)
@ -25,6 +25,7 @@ class IrisSystemThread(Thread):
Thread.__init__(self)
self.action = action
self.callback = callback
self.ioloop = tornado.ioloop.IOLoop.current()
self.script_path = pathlib.Path(__file__).parent / "system.sh"
def get_command(self, action=None, *, non_interactive=False):
@ -71,11 +72,15 @@ class IrisSystemThread(Thread):
if stderr:
error_string = os.fsdecode(stderr)
logger.error(error_string)
self.callback(None, {'error': error_string})
self.ioloop.add_callback(lambda: self.callback(None, {'error': error_string}))
elif proc.returncode > 0:
response_string = os.fsdecode(stdout)
logger.info(response_string)
self.ioloop.add_callback(lambda: self.callback(None, {'error': response_string}))
else:
response_string = os.fsdecode(stdout)
logger.info(response_string)
self.callback({'output': response_string}, None)
self.ioloop.add_callback(lambda: self.callback({'output': response_string}, None))
##
# Check if we have access to the system script (system.sh)

View File

@ -28,7 +28,7 @@ elif [[ $1 = "restart" ]]; then
elif [[ $1 = "local_scan" ]]; then
if [[ $IS_CONTAINER ]]; then
SCAN="$(mopidy --config /config/mopidy.conf local scan)"
SCAN="$(mopidy local scan)"
else
SCAN="$(sudo mopidyctl local scan)"
fi