Callbacks not finding self thread

This commit is contained in:
James Barnsley
2020-01-03 06:01:36 +13:00
parent fd66edfbe4
commit 10cc04adae
3 changed files with 33 additions and 29 deletions

View File

@ -456,7 +456,7 @@ class IrisCore(pykka.ThreadingActor):
callback = kwargs.get('callback', False)
# Trigger the action
IrisSystemThread('restart', self).start()
IrisSystemThread('restart', self.restart_callback).start()
self.broadcast(data={
'method': "restart_started"
@ -478,7 +478,8 @@ class IrisCore(pykka.ThreadingActor):
})
else:
self.broadcast(data={
'method': "restart_finished"
'method': "restart_finished",
'params': response
})
@ -493,7 +494,7 @@ class IrisCore(pykka.ThreadingActor):
})
# Trigger the action
IrisSystemThread('upgrade', self).start()
IrisSystemThread('upgrade', self.upgrade_callback).start()
response = {
'message': "Upgrade started"
@ -526,7 +527,7 @@ class IrisCore(pykka.ThreadingActor):
callback = kwargs.get('callback', False)
# Trigger the action
IrisSystemThread('local_scan', self).start()
IrisSystemThread('local_scan', self.local_scan_callback).start()
self.broadcast(data={
'method': "local_scan_started"
@ -1092,12 +1093,16 @@ class IrisCore(pykka.ThreadingActor):
'method': "test_started"
})
if (callback):
callback({
response = {
'message': "Running test... please wait"
})
}
IrisSystemThread('test', self).run()
if (callback):
callback(response)
else:
return response
IrisSystemThread('test', self.test_callback).run()
def test_callback(self, response, error):
if error:

View File

@ -6,10 +6,10 @@ import os, logging, subprocess, json
logger = logging.getLogger(__name__)
class IrisSystemThread(Thread):
def __init__(self, action, origin):
def __init__(self, action, callback):
Thread.__init__(self)
self.action = action
self.origin = origin
self.callback = callback
self.path = os.path.dirname(__file__)
##
@ -17,7 +17,6 @@ class IrisSystemThread(Thread):
##
def run(self):
logger.info("Running system action '"+self.action+"'")
callback_name = self.action+"_callback"
try:
self.can_run()
@ -43,20 +42,10 @@ class IrisSystemThread(Thread):
if stderr:
logger.error(stderr.decode())
getattr(self.origin, callback_name)(
None,
{
'error': stderr.decode()
}
)
self.callback(None, { 'error': stderr.decode() })
else:
logger.info(stdout.decode())
getattr(self.origin, callback_name)(
{
'output': stdout.decode()
},
None
)
self.callback({ 'output': stdout.decode() }, None)
@ -68,7 +57,7 @@ class IrisSystemThread(Thread):
def can_run(self, *args, **kwargs):
# Attempt an empty call to our system file
process = subprocess.Popen("sudo -n "+self.path+"/system.sh", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
process = subprocess.Popen("sudo -n "+self.path+"/system.sh check", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
result, error = process.communicate()
exitCode = process.wait()

View File

@ -1,9 +1,11 @@
#!/bin/bash
if [[ "$(pwd)" = "/iris/mopidy_iris/system.sh" ]]; then
if [[ "$(pwd)" = "/iris" ]]; then
IS_CONTAINER=true
echo -e "Detected as running in a Docker container"
else
IS_CONTAINER=false
echo -e "Not running in a Docker container"
fi
if [[ $1 = "upgrade" ]]; then
@ -17,9 +19,13 @@ if [[ $1 = "upgrade" ]]; then
echo -e "${UPGRADE}"
elif [[ $1 = "restart" ]]; then
if [[ $IS_CONTAINER ]]; then
echo -e "Cannot restart Mopidy when running in a Docker container"
exit 1
else
RESTART="$(sudo service mopidy restart)"
echo -e "${RESTART}"
fi
elif [[ $1 = "local_scan" ]]; then
@ -30,6 +36,9 @@ elif [[ $1 = "local_scan" ]]; then
fi
echo -e "${SCAN}"
elif [[ $1 = "check" ]]; then
echo -e "Access permitted"
elif [[ $1 = "test" ]]; then
sleep 3
@ -39,6 +48,7 @@ elif [[ $1 = "test" ]]; then
else
echo -e "Unsupported system task"
exit 1
fi
exit 0